Part Number Hot Search : 
128128 HA17807V B1006 SF101 DBCTB702 SP208CP D202RU 0LLLFD
Product Description
Full Text Search
 

To Download PIC18F65J94 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2012 microchip technology inc. ds30575a-page 1 pic18f97j94 family extreme low-power features: ? multiple power management options for extreme power reduction: -v bat allows for lowest power consumption on back-up battery (with or without rtcc) - deep sleep allows near total power-down with the ability to wake-up on external triggers - sleep and idle modes selectively shut down peripherals and/or core for substantial power reduction and fast wake-up ? alternate clock modes allow on-the-fly switching to a lower clock speed for selective power reduction ? extreme low-power current consumption for deep sleep: - wdt: 650 na @ 2v typical - rtcc: 650 na @ 32 khz, 2v typical - deep sleep current, 80 na typical universal serial bus features: ? usb v2.0 compliant ? low speed (1.5 mb/s) and full speed (12 mb/s) ? supports control, interrupt, isochronous and bulk transfers ? supports up to 32 endpoints (16 bidirectional) ? usb module can use any ram location on the device as usb endpoint buffers ? on-chip usb transceiver peripheral features: ? lcd display controller: - up to 60 segments by 8 commons - internal charge pump and low-power, internal resistor biasing - operation in sleep mode ? up to four external interrupt sources ? peripheral pin select lite (pps-lite): - allows independent i/o mapping of many peripherals ? four 16-bit timers/counters with prescaler: - can be paired as 32-bit timers/counters ? seven capture/compare/pwm (ccp) modules ? three enhanced capture/compare/pwm (eccp) modules: - one, two or four pwm outputs - selectable polarity - programmable dead time - auto-shutdown and auto-restart - pulse steering control peripheral features (continued): ? hardware real-time clock/calendar (rtcc): - runs in deep sleep and v bat modes ? two master synchronous serial ports (mssp) modules featuring: - 3-wire/4-wire spi (all 4 modes) - spi direct memory access (dma) channel w/1024 byte count -two i 2 c? modules support multi-master/slave mode and 7-bit/10-bit addressing ? four enhanced addressable usart modules: - support rs-485, rs-232 and lin/j2602 - on-chip hardware encoder/decoder for irda ? - auto-wake-up on auto-baud detect ? digital signal modulator provides on-chip ook, fsk and psk modulation for a digital signal stream ? high-current sink/source 18 ma/18 ma on all digital i/o ? configurable open-drain outputs on eccp/ccp/ usart/mssp ? extended microcontroller mode using 12, 16 or 20-bit addressing mode analog features: ? 10/12-bit, 24-channel analog-to-digital (a/d) converter: - conversion rate of 500 ksps (10-bit), 200 kbps (12-bit) - conversion available during sleep and idle ? three rail-to-rail enhanced analog comparators with programmable input/output configuration ? on-chip programmable voltage reference ? charge time measurement unit (ctmu): - used for capacitive touch sensing, up to 24 channels - time measurement down to 1 ns resolution - ctmu temperature sensing 8-bit lcd flash microcontroller with usb and xlp technology
pic18f97j94 family ds30575a-page 2 ? 2012 microchip technology inc. high-performance cpu: ? high-precision pll for usb ? two external clock modes, up to 64 mhz (16 mips) ? internal 31 khz oscillator ? high-precision internal oscillator with clock recovery from sosc to achieve 0.15% precision, 31 khz to 8 mhz or 64 mhz w/pll, .15% typical, 1.5% max. ? secondary oscillator using timer1 @ 32 khz ? c compiler optimized instruction set architecture ? two address generation units for separate read and write addressing of data memory special microcontroller features: ? operating voltage range of 2.0v to 3.6v ? two on-chip voltage regulators (1.8v and 1.2v) for regular and extreme low-power operation ? 20,000 erase/write cycle endurance flash program memory, typical ? flash data retention: 10 years minimum ? self-programmable under software control ? two configurable reference clock outputs (refo1 and refo2) ? in-circuit serial programming? (icsp?) ? fail-safe clock monitor operation: - detects clock failure and switches to on-chip, low-power rc oscillator ? power-on reset (por), power-up timer (pwrt) and oscillator start-up timer (ost) ? brown-out reset (bor) with operation below v bor , with regulator enabled ? high/low-voltage detect (hlvd) ? flexible watchdog timer (wdt) with its own rc oscillator for reliable operation ? standard and ultra low-power watchdog timers (wdt) for reliable operation in standard and deep sleep modes device pins memory remappable peripherals i 2 c? 10/12-bit a/d (ch) ctmu lcd (pixels) usb deep sleep w/v bat pps (lite) flash program (bytes) data sram (bytes) timers 8-bit/16-bit usart w/irda ? spi w/ dma comparators ccp/eccp pic18f97j94 100 128k 4k 4 4 2 3 y 2 24 y 480 y y lite pic18f87j94 80 128k 4k 4 4 2 3 y 2 24 y 352 y y lite pic18f67j94 64 128k 4k 4 4 2 3 y 2 16 y 224 y y lite pic18f96j99 100 96k 4k 4 4 2 3 y 2 24 y 480 y y lite pic18f86j99 80 96k 4k 4 4 2 3 y 2 24 y 352 y y lite pic18f66j99 64 96k 4k 4 4 2 3 y 2 16 y 224 y y lite pic18f96j94 100 64k 4k 4 4 2 3 y 2 24 y 480 y y lite pic18f86j94 80 64k 4k 4 4 2 3 y 2 24 y 352 y y lite pic18f66j94 64 64k 4k 4 4 2 3 y 2 16 y 224 y y lite pic18f95j94 100 32k 4k 4 4 2 3 y 2 24 y 480 y y lite pic18f85j94 80 32k 4k 4 4 2 3 y 2 24 y 352 y y lite PIC18F65J94 64 32k 4k 4 4 2 3 y 2 16 y 224 y y lite
? 2012 microchip technology inc. ds30575a-page 3 pic18f97j94 family pin diagrams 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 48 47 22 44 24 25 26 27 28 29 30 31 32 pic18f67j94 (128k) 1 46 45 23 43 42 41 40 39 v ss v dd av dd v dd v bat v cap v ss v ss v ss v dd 63 62 61 59 60 58 57 56 54 55 53 52 51 49 50 38 37 34 36 35 33 17 19 20 21 18 av ss 64 note: pinouts are subject to change. 64-pin tqfp, qfn mclr cted5/pgc/rb6 lcdbias2/rp29/w r /re1 lcdbias1/rp28/r d /re0 com4/seg28/an8/rp46/rg0 com5/seg29/an19/rp39/rg1 com6/seg30/an18/c3ina/rp42/rg2 com7/seg31/an17/c3inb/rp43/rg3 seg26/an16/c3inc/rp44/rtcc/rg4 seg25/an5/rp38/rf7 seg24/an11/c1ina/rp40/rf6 seg23/cv ref /an10/c1inb/rp35/rf5 d+/rf4 d-/rf3 seg20/an7/ctmui/c2inb/rp36/rf2 v ref +/an3/rp3/ra3 seg21/v ref -/an2/rp2/ra2 seg18/an1/rp1/ra1 seg19/an0/an1-/rp0/ra0 seg15/an4/lvdin/c1ina/c2ina/c3ina/rp5/ra5 seg14/an6/rp4/ra4 sosci/rc1 sosco/sclki/pwrlclk/rc0 seg27/rp18/uoe /cted11/rc6 seg22/rp19/cted12/rc7 seg13/an9/rp11/cted7/rc2 seg17/scl1/rp15/cted8/rc3 seg16/sda1/rp17/cted9/rc4 seg12/rp16/cted10/rc5 cted6/pgd/rb7 osc1/clki/rp10/ra7 osc2/clko/rp6/ra6 seg8/rp13/cted4/rb5 seg11/rp12/cted3/rb4 seg10/rp7/cted2/rb3 seg9/rp14/cted1/rb2 v lcap 2/rp9/rb1 v lcap 1/rp8/cted13/int0/rb0 seg7/rp27/refo2/psp7/rd7 seg6/scl2/rp26/psp6/rd6 seg5/sda2/rp25/psp5/rd5 seg4/rp24/psp4/rd4 seg3/rp23/psp3/rd3 seg2/rp22/psp2/rd2 seg1/rp21/psp1/rd1 seg0/rp20/psp0/rd0 lcdbias0/rp31/re7 com3/rp34/re6 com2/rp37/re5 com1/rp32/re4 com0/rp33/refo1/re3 lcdbias3/rp30/c s /re2 v usb 3 v 3
pic18f97j94 family ds30575a-page 4 ? 2012 microchip technology inc. pin diagrams (continued) 80 79 78 20 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 60 59 26 56 40 39 28 29 30 31 32 33 34 35 36 37 38 pic18f87j94 (128k) 17 18 19 1 76 77 58 57 27 55 54 53 52 51 v dd av dd v dd v cap v ss vss v ss v dd 75 74 73 71 72 70 69 68 66 67 65 64 63 61 62 50 49 46 48 47 45 44 43 42 41 21 23 24 25 22 av ss note: pinouts are subject to change. 80-pin tqfp mclr v bat cted6/pgd/rb7 cted5/pgc/rb6 a18/seg45/an21/rh2 a19/seg44/an20/rh3 ad9/lcdbias2/rp29/w r /re1 ad8/lcdbias1/rp28/r d /re0 com4/seg28/an8/rp46/rg0 com5/seg29/an19/rp39/rg1 com6/seg30/an18/c3ina/rp42/rg2 com7/seg31/an17/c3inb/rp43/rg3 seg26/an16/c3inc/rp44/rtcc/rg4 seg25/an5/rp38/rf7 seg24/an11/c1ina/rp40/rf6 seg23/cv ref /an10/c1inb/rp35/rf5 d+/rf4 d-/rf3 seg20/an7/c2inb/rp36/rf2 seg43/an15/rh7 seg42/an14/c1inc/rh6 seg41/an13/c2ind/rh5 seg40/an12/c2inc/rh4 v usb 3 v 3 v ref +/an3/rp3/ra3 seg21/v ref -/an2/rp2/ra2 seg18/an1/rp1/ra1 seg19/an0/an1-/rp0/ra0 seg15/an4/lvdin/c1ina/c2ina/c3ina/rp5/ra5 seg14/an6/rp4/ra4 sosci/rc1 sosco/sclki/pwrlclk/rc0 seg27/rp18/uoe /cted11/rc6 seg22/rp19/cted12/rc7 ba0/seg39/rj4 ce/seg38/rj5 lb /seg37/rj6 ub /seg36/rj7 seg13/an9/rp11/cted7/rc2 seg17/scl1/rp15/cted8/rc3 seg16/sda1/rp17/cted9/rc4 seg12/rp16/cted10/rc5 osc1/clki/rp10/ra7 osc2/clko/rp6/ra6 seg8/rp13/cted4/rb5 seg11/rp12/cted3/rb4 seg10/rp7/cted2/rb3 seg9/rp14/cted1/rb2 v lcap 2/rp9/rb1 v lcap 1/rp8/cted13/int0/rb0 wrh /seg35/rj3 wrl /seg34/rj2 oe/seg33/rj1 ale/seg32/rj0 ad7/seg7/rp27/refo2/psp7/rd7 ad6/seg6/scl2/rp26/psp6/rd6 ad5/seg5/sda2/rp25/psp5/rd5 ad4/seg4/rp24/psp4/rd4 ad3/seg3/rp23/psp3/rd3 ad2/seg2/rp22/psp2/rd2 ad1/seg1/rp21/psp1/rd1 v ss ad0/seg0/rp20/psp0/rd0 ad15/lcdbias0/rp31/re7 ad14/com3/rp34/re6 ad13/com2/rp37/re5 ad12/com1/rp32/re4 ad11/com0/rp33/refo1/re3 ad10/lcdbias3/rp30/c s /re2 a16/seg47/an23/rh0 a17/seg46/an22/rh1
? 2012 microchip technology inc. ds30575a-page 5 pic18f97j94 family pin diagrams (continued) 92 94 93 91 90 89 88 87 86 85 84 83 82 81 80 79 78 20 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 65 64 63 62 61 60 59 26 56 45 44 43 42 41 40 39 28 29 30 31 32 33 34 35 36 37 38 pic18f97j94 (128k) 17 18 19 21 22 95 1 76 77 72 71 70 69 68 67 66 75 74 73 58 57 24 23 25 96 98 97 99 27 46 47 48 49 50 55 54 53 52 51 100 v ss v bat av dd av ss v ss v dd v ss v cap v dd v dd v ss note: pinouts are subject to change. 100-pin tqfp v dd mclr seg51/rl3 seg52/rl4 ub /seg36/rj7 cted6/pgd/rb7 seg58/rk2 seg59/rk3 cted5/pgc/rb6 v ss rg6 rg7 a18/seg45/an21/rh2 a19/seg44/an20/rh3 ad9/lcdbias2/rp29/w r /re1 ad8/lcdbias1/rp28/r d /re0 com4/seg28/an8/rp46/rg0 com5/seg29/an19/rp39/rg1 com6/seg30/an18/c3ina/rp42/rg2 com7/seg31/an17/c3inb/rp43/rg3 seg49/rl1 seg26/an16/c3inc/rp44/rtcc/rg4 seg50/rl2 seg25/an5/rp38/rf7 seg24/an11/c1ina/rp40/rf6 seg23/cv ref /an10/c1inb/rp35/rf5 d+/rf4 d-/rf3 seg20/an7/ctmui/c2inb/rp36/rf2 seg43/an15/rh7 seg42/an14/c1inc/rh6 seg41/an13/c2ind/rh5 seg40/an12/c2inc/rh4 seg53/rl5 v ref +/an3/rp3/ra3 seg21/v ref -/an2/rp2/ra2 seg18/an1/rp1/ra1 seg19/an0/an1-/rp0/ra0 seg54/rl6 seg55/rl7 seg15/an4/lvdin/c1ina/c2ina/c3ina/rp5/ra5 seg14/an6/rp4/ra4 sosci/rc1 sosco/sclki/pwrlclk/rc0 seg56/rk0 seg27/rp18/uoe /cted11/rc6 seg22/rp19/cted12/rc7 ba0/seg39/rj4 ce/seg38/rj5 lb /seg37/rj6 seg13/an9/rp11/cted7/rc2 seg17/scl1/rp15/cted8/rc3 seg57/rk1 seg16/sda1/rp17/cted9/rc4 seg12/rp16/cted10/rc5 osc1/clki/rp10/ra7 osc2/clko/rp6/ra6 ddio0/seg60/rk4 seg8/rp13/cted4/rb5 seg11/rp12/cted3/rb4 seg10/rp7/cted2/rb3 seg9/rp14/cted1/rb2 ddio1/seg61/rk5 v lcap 2/rp9/rb1 v lcap 1/rp8/cted13/int0/rb0 wrh /seg35/rj3 wrl /seg34/rj2 oe/seg33/rj1 ale/seg32/rj0 ad7/seg7/rp27/refo2/psp7/rd7 ad6/seg6/scl2/rp26/psp6/rd6 seg62/rk6 ad5/seg5/sda2/rp25/psp5/rd5 ad4/seg4/rp24/psp4/rd4 ad3/seg3/rp23/psp3/rd3 ad2/seg2/rp22/psp2/rd2 seg63/rk7 ad1/seg1/rp21/psp1/rd1 ad0/seg0/rp20/psp0/rd0 seg48/rl0 ad15/lcdbias0/rp31/re7 ad14/com3/rp34/re6 ad13/com2/rp37/re5 ad12/com1/rp32/re4 ad11/com0/rp33/refo1/re3 ad10/lcdbias3/rp30/c s /re2 a16/seg47/an23/rh0 a17/seg46/an22/rh1 v usb 3 v 3
pic18f97j94 family ds30575a-page 6 ? 2012 microchip technology inc. table of contents 1.0 device overview ............................................................................................................. ............................................................. 9 2.0 guidelines for getting started with pic18fj microcontrollers ................................................................ ................................... 31 3.0 oscillator configurations .................................... ............................................................... ......................................................... 37 4.0 power-managed modes ......................................................................................................... .................................................... 65 5.0 reset ....................................................................................................................... ................................................................... 85 6.0 memory organization ......................................................................................................... ...................................................... 113 7.0 flash program memory........................................................................................................ .................................................... 143 8.0 external memory bus ......................................................................................................... ...................................................... 153 9.0 8 x 8 hardware multiplier................................................................................................... ....................................................... 165 10.0 interrupts ................................................................................................................. ................................................................. 167 11.0 i/o ports .................................................................................................................. ................................................................. 197 12.0 data signal modulator ...................................................................................................... ........................................................ 235 13.0 liquid crystal display (lcd) controller.................................................................................... ................................................ 245 14.0 timer0 module .............................................................................................................. ........................................................... 281 15.0 timer1/3/5 modules......................................................................................................... ......................................................... 284 16.0 timer2/4/6/8 modules....................................................................................................... ........................................................ 294 17.0 real-time clock and calendar (rtcc) ........................................................................................ ........................................... 297 18.0 enhanced capture/compare/pwm (eccp) module................................................................................. ............................... 317 19.0 capture/compare/pwm (ccp) modules .......................................................................................... ....................................... 339 20.0 master synchronous serial port (mssp) module ............................................................................... ..................................... 351 21.0 enhanced universal synchronous asynchronous receiver transmitter (eusart) .................................................. ............. 411 22.0 12-bit a/d converter with threshold scan................................................................................... ............................................ 435 23.0 comparator module.......................................................................................................... ........................................................ 489 24.0 comparator voltage reference module ........................................................................................ ........................................... 497 25.0 high/low-voltage detect (hlvd)............................................................................................. ................................................ 501 26.0 charge time measurement unit (ctmu) ........................................................................................ ........................................ 507 27.0 universal serial bus (usb) ................................................................................................. ..................................................... 525 28.0 special features of the cpu ................................................................................................ .................................................... 553 29.0 instruction set summary .................................................................................................... ...................................................... 575 30.0 development support........................................................................................................ ....................................................... 625 31.0 electrical characteristics ................................................................................................. ......................................................... 629 32.0 packaging information...................................................................................................... ........................................................ 663 appendix a: revision history................................................................................................... .......................................................... 677 index .......................................................................................................................... ....................................................................... 679
? 2012 microchip technology inc. ds30575a-page 7 pic18f97j94 family to our valued customers it is our intention to provide our valued customers with the best documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regar ding this publication, please contact the marketing communications department via e-mail at docerrors@microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/documentation issues become known to us, we will publish an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particular device, please check with one of the following: ? microchip?s worldwide web site; http://www.microchip.com ? your local microchip sales office (see last page) when contacting a sales office, please specify which device, re vision of silicon and data sheet (include literature number) you are using. customer notification system register on our web site at www.microchip.com to receive the most current information on all of our products.
pic18f97j94 family ds30575a-page 8 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 9 pic18f97j94 family 1.0 device overview this document contains device-specific information for the following devices: this family introduces a new line of low-voltage lcd microcontrollers with universal serial bus (usb). it combines all the main traditional advantage of all pic18 microcontrollers, namely, high computational performance and a rich feature set at an extremely competitive price point. these features make the pic18f97j94 family a logical choice for many high-performance applications, where cost is a primary consideration. 1.1 core features 1.1.1 technology all of the devices in the pic18f97j94 family incorporate a range of features that c an significantly reduce power consumption during operation. key items include: ? alternate run modes: by clocking the controller from the timer1 source or the internal rc oscilla- tor, power consumption during code execution can be reduced. ? multiple idle modes: the controller can also run with its cpu core disabled but the peripherals still active. in these states, power consumption can be reduced even further. ? on-the-fly mode switching: the power-managed modes are invoked by user code during operation, allowing the user to incorporate power-saving ideas into their application?s software design. ? xlp: an extra low-power sleep, bor, rtcc and watchdog timer. 1.1.2 oscillator options and features all of the devices in the pic18f97j94 family offer differ- ent oscillator options, allowing users a range of choices in developing application hardware. these include: ? two crystal modes (hs, ms) ? one external clock mode (ec) ? a phase lock loop (pll) frequency multiplier, which allows clock speeds of up to 64 mhz. ? a fast internal oscillator (frc) block that provides an 8 mhz clock (0.15% accuracy) with active clock tuning (act) from usb or sosc source. - offers multiple divider options from 8 mhz to 500 khz - frees the two oscillator pins for use as additional general purpose i/o ? a separate low-power internal rc oscillator (lprc) (31 khz nominal) for low-power, timing-insensitive applications. the internal oscillator block provides a stable reference source that gives the family additional features for robust operation: ? fail-safe clock monitor (fscm): this option constantly monitors the main clock source against a reference signal provided by the internal oscillator. if a clock failure occurs, the controller is switched to the internal oscillator, allowing for continued low-speed operation or a safe application shutdown. ? two-speed start-up (ieso): this option allows the internal oscillator to serve as the clock source from power-on reset, or wake-up from sleep mode, until the primary clock source is available. ? pic18f97j94 ? pic18f96j94 ? pic18f87j94 ? pic18f86j94 ? pic18f67j94 ? pic18f66j94 ? pic18f96j99 ? pic18f95j94 ? pic18f86j99 ? pic18f85j94 ? pic18f66j99 ? PIC18F65J94
pic18f97j94 family ds30575a-page 10 ? 2012 microchip technology inc. 1.1.3 memory options the pic18f97j94 family provides ample room for application code, from 32 kbytes to 128 kbytes of code space. the flash cells for program memory are rated to last up to 20,000 erase/write cycles. data retention without refresh is conservatively estimated to be greater than 10 years. the flash program memory is readable and writable. during normal operation, the pic18f97j94 family also provides plenty of room for dynamic application data with up to 3,578 bytes of data ram. 1.1.4 universal serial bus (usb) devices in the pic18f97j94 family incorporate a fully-featured usb communications module with a built-in transceiver that is compliant with the usb specification revision 2.0. the module supports both low-speed and full-speed communication for all supported data transfer types. 1.1.5 external memory bus should 128 kbytes of memory be inadequate for an application, the 80-pin and 100-pin members of the pic18f97j94 family have an external memory bus (emb), enabling the controller?s internal program counter to address a memory space of up to 2 mbytes. this is a level of data access that few 8-bit devices can claim and enables: ? using combinations of on-chip and external memory of up to 2 mbytes ? using external flash memory for reprogrammable application code or large data tables ? using external ram devices for storing large amounts of variable data 1.1.6 extended instruction set the pic18f97j94 family implements the optional extension to the pic18 instruction set, adding eight new instructions and an indexed addressing mode. enabled as a device configuration option, the extension has been specifically designed to optimize re-entrant application code originally developed in high-level languages, such as ?c?. 1.1.7 easy migration all devices share the same rich set of peripherals. this provides a smooth migration path within the device family as applications evolve and grow. the consistent pinout scheme, used throughout the entire family, also aids in migrating to the next larger device. this is true when moving between the 64-pin members, between the 80-pin members, between the 100-pin members or even jumping from 64-pin to 80-pin to 100-pin devices. the pic18f97j94 family is also largely pin compatible with other pic18 families, such as the pic18f87j90, pic18f87j11 and the pic18f87j50. this allows a new dimension to the evolution of applications, allowing developers to select different price points within microchip?s pic18 portfolio, while maintaining a similar feature set. 1.2 lcd controller the on-chip lcd driver includes many features that make the integration of displays in low-power applica- tions easier. these include an integrated voltage regu- lator with charge pump and an integrated internal resistor ladder that allows contrast control in software and display operation above device v dd .
? 2012 microchip technology inc. ds30575a-page 11 pic18f97j94 family 1.3 other special features ? communications: the pic18f97j94 family incorporates a range of serial communication peripherals, including usb, four enhanced addressable usarts with irda, and two master synchronous serial port mssp modules capable of both spi and i 2 c? (master and slave) modes of operation. ? ccp modules: pic18f97j94 family devices incorporate up to seven capture/compare/pwm (ccp) modules. up to six different time bases can be used to perform several different operations at once. ? eccp modules: the pic18f97j94 family has three enhanced ccp (eccp) modules to maximize flexibility in control applications: - up to eight different time bases for performing several different operations at once - up to four pwm outputs for each module ? for a total of 12 pwms - other beneficial features, such as polarity selection, programmable dead time, auto-shutdown and restart, and half-bridge and full-bridge output modes ? 12-bit a/d converter: the pic18f97j94 family has a software selectable, 10/12-bit analog-to-digital (a/d) converter. it incorporates programmable acquisition time, allowing for a channel to be selected and a conversion to be initiated without waiting for a sampling period, and thus, reducing code overhead. ? charge time measurement unit (ctmu): the ctmu is a flexible analog module that provides accurate differential time measurement between pulse sources, as well as asynchronous pulse generation. ? together with other on-chip analog modules, the ctmu can precisely measure time, measure capacitance or relative changes in capacitance, or generate output pulses that are independent of the system clock. ? lp watchdog timer (wdt): this enhanced version incorporates a 22-bit prescaler, allowing an extended time-out range that is stable across operating voltage and temperature. see section 31.0 ?electrical characteristics? for time-out periods. ? real-time clock and calendar module (rtcc): the rtcc module is intended for appli- cations requiring that accurate time be maintained for extended periods of time, with minimum to no intervention from the cpu. ? the module is a 100-year clock and calendar with automatic leap year detection. the range of the clock is from 00:00:00 (midnight) on january 1, 2000 to 23:59:59 on december 31, 2099. 1.4 details on individual family members devices in the pic18f97j94 family are available in 64-pin, 80-pin and 100-pin packages. block diagrams for the two groups are shown in figure 1-1 , figure 1-2 and figure 1-3 . the devices are differentiated from each other in these ways: ? flash program memory: - pic18fx5j94 ? 32 kbytes - pic18fx6j94 ? 64 kbytes - pic18fx6j99 ? 96 kbytes - pic18fx7j94 ? 128 kbytes ? data ram: - all devices ? 4 kbytes ? i/o ports: - pic18f6xj9x (64-pin devices) ? seven bidirectional ports - pic18f8xj9x (80-pin devices) ? nine bidirectional ports - pic18f9xj9x (100-pin devices) ? eleven bidirectional ports ? a/d channels: - pic18f6xjxx (64-pin devices) ? 16 channels - pic18f8xjxx (80-pin devices) ? 24 channels - pic18f9xjxx (100-pin devices) ? 24 channels all other features for devices in this family are identical. these are summarized in table 1-1 , tab l e 1 - 2 and table 1-3 . the pinouts for all devices are listed in ta bl e 1 - 4 .
pic18f97j94 family ds30575a-page 12 ? 2012 microchip technology inc. table 1-1: device features for the 64-pin devices table 1-2: device features for the 80-pin devices features PIC18F65J94 pic18f66j94 pic18f66j99 pic18f67j94 operating frequency dc ? 64 mhz program memory (bytes) 32k 64k 96k 128k program memory (instructions) 16,384 32,768 49,152 65,536 data memory (bytes) 4k 4k 4k 4k interrupt sources 42 48 i/o ports ports a, b, c, d, e, f, g parallel communications parallel slave port (psp) timers 8 comparators 3 lcd 224 pixels ctmu yes rtcc yes enhanced capture/compare/pwm modules 3 eccps and 7 ccps serial communications two mssps, four enhanced usarts (eusart) and usb 10/12-bit analog-to-digital module 16 input channels resets (and delays) por, bor, cm reset instruction, stack full, stack underflow, mclr , wdt (pwrt, ost) instruction set 75 instructions, 83 with extended instruction set enabled packages 64-pin qfn, 64-pin tqfp features pic18f85j94 pic18f86j94 pic18f86j99 pic18f87j94 operating frequency dc ? 64 mhz program memory (bytes) 32 k 64k 96k 128k (up to 2 mbytes with extended memory) program memory (instructions) 16,384 32,768 49,152 65,536 data memory (bytes) 4k 4k 4k 4k interrupt sources 42 48 i/o ports ports a, b, c, d, e, f, g, h, j parallel communications parallel slave port (psp) timers 8 comparators 3 lcd 352 pixels ctmu yes rtcc yes enhanced capture/compare/pwm modules 3 eccps and 7 ccps serial communications two mssps, four enhanced usarts (eusart) and usb 12-bit analog-to-digital module 24 input channels resets (and delays) por, bor, cm reset instruction, stack full, stack underflow, mclr , wdt (pwrt, ost) instruction set 75 instructions, 83 with extended instruction set enabled packages 80-pin tqfp
? 2012 microchip technology inc. ds30575a-page 13 pic18f97j94 family table 1-3: device features for the 100-pin devices features pic18f95j94 pic18f96j94 pic18f96j99 pic18f97j94 operating frequency dc ? 64 mhz program memory (bytes) 32 k 64k 96k 128k (up to 2 mbytes with extended memory) program memory (instructions) 16,384 32,768 49,152 65,536 data memory (bytes) 4k 4k 4k 4k interrupt sources 42 48 i/o ports ports a, b, c, d, e, f, g, h, j, k, l parallel communications parallel slave port (psp) timers 8 comparators 3 lcd 480 pixels ctmu yes rtcc yes enhanced capture/compare/pwm modules 3 eccps and 7 ccps serial communications two mssps, four enhanced usarts (eusart) and usb 12-bit analog-to-digital module 24 input channels resets (and delays) por, bor, cm reset instruction, stack full, stack underflow, mclr , wdt (pwrt, ost) instruction set 75 instructions, 83 with extended instruction set enabled packages 100-pin tqfp
pic18f97j94 family ds30575a-page 14 ? 2012 microchip technology inc. figure 1-1: 64-pin device block diagram porta data latch data memory (4 kbytes) address latch data address<12> 12 access bsr fsr0 fsr1 fsr2 inc/dec logic address 4 12 4 pch pcl pclath 8 31-level stack program counter prodl prodh 8 x 8 multiply 8 bitop 8 8 alu<8> address latch program memory data latch 20 8 8 table pointer<21> inc/dec logic 21 8 data bus<8> table latch 8 12 3 pclatu pcu note 1: see table 1-4 for i/o port pin descriptions. 2: ra6 and ra7 are only available as digital i/o in se lect oscillator modes. for more information, see section 3.0 ?oscillator configurations? . eusart1 comparator mssp1/2 3/5 2/4/6/8 ctmu timer1 a/d 10/12-bit w instruction bus <16> stkptr bank 8 state machine control signals decode 8 8 eusart2 rom latch portc portd porte portf portg ra<7:0> (1,2) rc<7:0> (1) rd<7:0> (1) re<7:0> (1) rf<7:2> (1) rg<4:0> (1) portb rb<7:0> (1) osc1/clki osc2/clko v dd , v ss timing generation mclr power-up timer oscillator start-up timer power-on reset watchdog timer bor and hlvd precision reference band gap intrc oscillator regulator voltage v ddcore /v cap 8 mhz oscillator timer0 4/5/6/7/8/9/10 rtcc timer timer 1/2/3 ccp eccp 1/2/3 usb eusart3 eusart4 ir instruction decode and control lcd 224 pixels
? 2012 microchip technology inc. ds30575a-page 15 pic18f97j94 family figure 1-2: 80-pin device block diagram instruction decode and control data latch address latch data address<12> 12 access bsr fsr0 fsr1 fsr2 inc/dec logic address 4 12 4 pch pcl pclath 8 31-level stack program counter prodl prodh 8 x 8 multiply 8 bitop 8 8 alu<8> address latch program memory data latch 20 8 8 table pointer<21> inc/dec logic 21 8 data bus<8> table latch 8 12 3 pclatu pcu w instruction bus <16> stkptr bank 8 state machine control signals decode 8 8 rom latch osc1/clki osc2/clko v dd , v ss mclr power-up timer oscillator start-up timer power-on reset watchdog timer precision reference band gap regulator voltage v ddcore /v cap porta portc portd porte portf portg ra<7:0> (1,2) rc<7:0> (1) rd<7:0> (1) rf<7:2> (1) rg<4:0> (1) portb rb<7:0> (1) porth rh<7:0> (1) portj rj<7:0> (1) note 1: see table 1-4 for i/o port pin descriptions. 2: ra6 and ra7 are only available as digital i/o in select oscillator modes. see section 3.0 ?oscillator configurations? for more information. timing generation intrc oscillator 8 mhz oscillator re<7:0> (1) bor and hlvd data memory (4 kbytes) eusart1 comparator mssp1/2 3/5 2/4/6/8 ctmu timer1 a/d 12-bit eusart2 timer0 4/5/6/7/8/9/10 rtcc timer timer 1/2/3 ccp eccp 1/2/3 system bus interface ad<15:0>, a<19:16> (multiplexed with portd, porte and porth) usb eusart4 eusart3 usb usb emb ir lcd 352 pixels
pic18f97j94 family ds30575a-page 16 ? 2012 microchip technology inc. figure 1-3: 100-pin devi ce block diagram instruction decode and control data latch address latch data address<12> 12 bsr fsr0 fsr1 fsr2 inc/dec logic address 4124 pch pcl pclath 8 31-level stack program counter prodl prodh 8 x 8 multiply 8 bitop 8 8 alu<8> address latch program memory data latch 20 8 8 table pointer<21> inc/dec logic 21 8 data bus<8> table latch 8 ir 12 3 pclatu pcu w instruction bus <16> stkptr 8 state machine control signals decode 8 8 rom latch osc1/clki osc2/clko v dd , v ss mclr power-up timer oscillator start-up timer power-on reset watchdog timer precision reference band gap regulator voltage v ddcore /v cap porta portc portd porte portf portg ra<7:0> (1,2) rc<7:0> (1) rd<7:0> (1) rf<7:2> (1) rg<4:0>, portb rb<7:0> (1) porth rh<7:0> (1) portj rj<7:0> (1) note 1: see table 1-4 for i/o port pin descriptions. 2: ra6 and ra7 are only available as digital i/o in select oscillator modes. see section 3.0 ?oscillator configurations? for more information. timing generation intrc oscillator 8 mhz oscillator re<7:0> (1) bor and hlvd data memory (4 kbytes) eusart1 comparator mssp1/2 3/5 2/4/6/8 ctmu timer1 a/d 12-bit eusart2 timer0 4/5/6/7/8/9/10 rtcc timer timer 1/2/3 ccp eccp 1/2/3 system bus interface ad<15:0>, a<19:16> (multiplexed with portd, porte and porth) usb portk rk<7:0> (1) portl eusart4 eusart3 usb usb emb rl<7:0> (1) rg<7:6> (1) access bank lcd 480 pixels
? 2012 microchip technology inc. ds30575a-page 17 pic18f97j94 family table 1-4: pic18f97j94 pi nout i/o descriptions pin name pin number pin type buffer type description 100 80 64 mcl r 11 9 7 i st master clear (input) or programming voltage (input). this pin is an active-low reset to the device. osc1/clki/rp10/ra7 osc1 clki rp10 ra7 61 49 39 i i i/o i/o st cmos st/dig st/dig oscillator crystal or external clock input. oscillator crystal input. external clock source input. always associated with pin function, osc1. (see related osc1/clki,osc2/clko pins.) remappable peripheral pin 10 input/output. general purpose i/o pin. osc2/clko/rp6/ra6 osc2 clko rp6 ra6 62 50 40 o o i/o i/o ? dig st/dig st/dig oscillator crystal or clock output. oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. in certain oscillator modes, osc2 pin outputs clko, which has 1/4 the frequency of osc1 and denotes the instruction cycle rate. remappable peripheral pin 6 input/output. general purpose i/o pin. legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) i2c = i 2 c?/smbus
pic18f97j94 family ds30575a-page 18 ? 2012 microchip technology inc. seg19/an0/an1-/rp0/ra0 seg19 an0 an1- rp0 ra0 37 30 24 o i i i/o i/o analog analog analog st/dig st/dig seg19 output for lcd. analog input 0. a/d negative input channel. remappable peripheral pin 0 input/output. general purpose i/o pin. seg18/an1/rp1/ra1 seg18 an1 rp1 ra1 36 29 23 o i i/o i/o analog analog st/dig st/dig seg18 output for lcd. analog input 1. remappable peripheral pin 1 input/output. general purpose i/o pin. seg21/v ref -/an2/rp2/ra2 seg21 v ref - an2 rp2 ra2 34 28 22 o i i i/o i/o analog analog analog st/dig st/dig seg21 output for lcd. a/d reference voltage (low) input. analog input 2. remappable peripheral pin 2 input/output. general purpose i/o pin. v ref +/an3/rp3/ra3 v ref + an3 rp3 ra3 33 27 21 i i i/o i/o analog analog st/dig st/dig a/d reference voltage (high) input. analog input 3. remappable peripheral pin 3 input/output. general purpose i/o pin. seg14/an6/rp4/ra4 seg14 an6 rp4 ra4 43 34 28 o i i/o i/o analog analog st/dig st/dig seg14 output for lcd. analog input 6. remappable peripheral pin 4 input/output. general purpose i/o pin. seg15/an4/lvdin/c1ina/ c2ina/c3ina/rp5/ra5 seg15 an4 lvdin c1ina c2ina c3ina rp5 ra5 42 33 27 o i i i i i i/o i/o analog analog analog analog analog analog st/dig st/dig seg15 output for lcd. analog input 4. high/low-voltage detect (hlvd) input. comparator 1 input a. comparator 2 input a. comparator 3 input a. remappable peripheral pin 5 input/output. general purpose i/o pin. table 1-4: pic18f97j94 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 100 80 64 legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) i2c = i 2 c?/smbus
? 2012 microchip technology inc. ds30575a-page 19 pic18f97j94 family v lcap 1/rp8/cted13/int0/rb0 v lcap 1 rp8 cted13 int0 rb0 73 58 48 i i/o i i i/o analog st/dig st st st/dig lcd drive charge pump capacitor input 1. remappable peripheral pin 8 input/output. ctmu edge 13 input. external interrupt 0. general purpose i/o pin. v lcap 2/rp9/rb1 v lcap 2 rp9 rb1 72 57 47 i i/o i/o analog st/dig st/dig lcd drive charge pump capacitor input 2. remappable peripheral pin 9 input/output. general purpose i/o pin. seg9/rp14/cted1/rb2 seg9 rp14 cted1 rb2 70 56 46 o i/o i i/o analog st/dig st st/dig seg9 output for lcd. remappable peripheral pin 14 input/output. ctmu edge 1 input. general purpose i/o pin. seg10/rp7/cted2/rb3 seg10 rp7 cted2 rb3 69 55 45 o i/o i i/o analog st/dig st st/dig seg10 output for lcd. remappable peripheral pin 7 input/output. ctmu edge 2 input. general purpose i/o pin. seg11/rp12/cted3/rb4 seg11 rp12 cted3 rb4 68 54 44 o i/o i i/o analog st/dig st st/dig seg11 output for lcd. remappable peripheral pin 12 input/output. ctmu edge 3 input. general purpose i/o pin. seg8/rp13/cted4/rb5 seg8 rp13 cted4 rb5 67 53 43 o i/o i i/o analog st/dig st st/dig seg8 output for lcd. remappable peripheral pin 13 input/output. ctmu edge 4 input. general purpose i/o pin. pgc/cted5/rb6 pgc cted5 rb6 65 52 42 i/o i i/o st/dig st st/dig in-circuit debugger and icsp? programming clock pin. ctmu edge input. general purpose i/o pin. pgd/cted6/rb7 pgd cted6 rb7 58 47 37 i/o i i/o st/dig st st/dig in-circuit debugger and icsp? programming data pin. ctmu edge 6 input. general purpose i/o pin. table 1-4: pic18f97j94 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 100 80 64 legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) i2c = i 2 c?/smbus
pic18f97j94 family ds30575a-page 20 ? 2012 microchip technology inc. sosco/sclki/pwrlclk/rc0 sosco sclki pwrlclk rc0 45 36 30 o i i i/o ? st st st/dig sosc oscillator output. digital sosc input. sosc input at 50 hz or 60 hz only (rtcclksel<1:0> = 11 or 10 ). general purpose i/o pin. sosci/rc1 sosci rc1 44 35 29 i i/o analog st/dig timer1 oscillator input. general purpose i/o pin. seg13/an9/rp11/cted7/rc2 seg13 an9 rp11 cted7 rc2 53 43 33 o i i/o i i/o analog analog st/dig st st/dig seg13 output for lcd. analog input 9. remappable peripheral pin 11 input/output. ctmu edge 7 input. general purpose i/o pin. seg17/scl1/rp15/cted8/rc3 seg17 scl1 rp15 cted8 rc3 54 44 34 o i/o i/o i i/o analog i2c st/dig st st/dig seg17 output for lcd. i 2 c clock input/output. remappable peripheral pin 15 input/output. ctmu edge 8 input. general purpose i/o pin. seg16/sda1/rp17/cted9/rc4 seg16 sda1 rp17 cted9 rc4 56 45 35 o i/o i/o i i/o analog i2c st/dig st st/dig seg16 output for lcd. i 2 c data input/output. remappable peripheral pin 17 input/output. ctmu edge 9 input. general purpose i/o pin. seg12/rp16/cted10/rc5 seg12 rp16 cted10 rc5 57 46 36 o i/o i i/o analog st/dig st st/dig seg12 output for lcd. remappable peripheral pin 16 input/output. ctmu edge 10 input. general purpose i/o pin. seg27/rp18/uoe /cted11/rc6 seg27 rp18 u oe / cted11 rc6 47 37 31 o i/o o i i/o analog st/dig dig st st/dig seg27 output for lcd. remappable peripheral pin 18 input/output. external usb transceiver noe output. ctmu edge 11 input. general purpose i/o pin. seg22/rp19/cted12/rc7 seg22 rp19 cted12 rc7 48 38 32 o i/o i i/o analog st/dig st st/dig seg22 output for lcd. remappable peripheral pin 19 input/output. ctmu edge 12 input. general purpose i/o pin. table 1-4: pic18f97j94 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 100 80 64 legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) i2c = i 2 c?/smbus
? 2012 microchip technology inc. ds30575a-page 21 pic18f97j94 family ad0/seg0/rp20/psp0/rd0 ad0 seg0 rp20 psp0 rd0 90 72 58 i/o o i/o i/o i/o ttl/dig analog st/dig st/dig st/dig external memory address/data 0. seg0 output for lcd. remappable peripheral pin 20 input/output. parallel slave port data. general purpose i/o pin. ad1/seg1/rp21/psp1/rd1 ad1 seg1 rp21 psp1 rd1 86 69 55 i/o o i/o i/o i/o ttl/dig analog st/dig st/dig st/dig external memory address/data 1. seg1 output for lcd. remappable peripheral pin 21 input/output. parallel slave port data. general purpose i/o pin. ad2/seg2/rp22/psp2/rd2 ad2 seg2 rp22 psp2 rd2 84 68 54 i/o o i/o i/o i/o ttl/dig analog st/dig st/dig st/dig external memory address/data 2. seg2 output for lcd. remappable peripheral pin 22 input/output. parallel slave port data. general purpose i/o pin. ad3/seg3/rp23/psp3/rd3 ad3 seg3 rp23 psp3 rd3 83 67 53 i/o o i/o i/o i/o ttl/dig analog st/dig st/dig st/dig external memory address/data 3. seg3 output for lcd. remappable peripheral pin 3 input/output. parallel slave port data. general purpose i/o pin. ad4/seg4/rp24/psp4/rd4 ad4 seg4 rp24 psp4 rd4 82 66 52 i/o o i/o i/o i/o ttl/dig analog st/dig st/dig st/dig external memory address/data 4. seg4 output for lcd. remappable peripheral pin 24 input/output. parallel slave port data. general purpose i/o pin. ad5/seg5/sda2/rp25/psp5/rd5 ad5 seg5 sda2 rp25 psp5 rd5 81 65 51 i/o o i/o i/o i/o i/o ttl/dig analog i2c st/dig st/dig st/dig external memory address/data 5. seg5 output for lcd. i 2 c data input/output. remappable peripheral pin 25 input/output. parallel slave port data. general purpose i/o pin. ad6/seg6/scl2/rp26/psp6/rd6 ad6 seg6 scl2 rp26 psp6 rd6 79 64 50 i/o o i/o i/o i/o i/o ttl/dig analog i2c st/dig st/dig st/dig external memory address/data 6. seg6 output for lcd. i 2 c clock input/output. remappable peripheral pin 26 input/output. parallel slave port data. general purpose i/o pin. ad7/seg7/rp27/refo2/ psp7/rd7 ad7 seg7 rp27 refo2 psp7 rd7 78 63 49 i/o o i/o o i/o i/o ttl/dig analog st/dig dig st/dig st/dig external memory address/data 7. seg7 output for lcd. remappable peripheral pin 27 input/output. reference output clock. parallel slave port data general purpose i/o pin. table 1-4: pic18f97j94 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 100 80 64 legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) i2c = i 2 c?/smbus
pic18f97j94 family ds30575a-page 22 ? 2012 microchip technology inc. ad8/lcdbias1/rp28/rd /re0 ad8 lcdbias1 rp28 rd re0 4 4 2 i/o i i/o i i/o ttl/dig analog st/dig ttl st/dig external memory address/data 8. bias1 input for lcd. remappable peripheral pin 28 input/output. parallel slave port read strobe. general purpose i/o pin. ad9/lcdbias2/rp29/wr /re1 ad9 lcdbias2 rp29 wr re1 3 3 1 i/o i i/o i i/o ttl/dig analog st/dig ttl st/dig external memory address/data 9. bias2 input for lcd. remappable peripheral pin 29 input/output. parallel slave port write strobe. general purpose i/o pin. ad10/lcdbias3/rp30/cs /re2 ad10 lcdbias3 rp30 cs re2 98 78 64 i/o i i/o i i/o ttl/dig analog st/dig ttl st/dig external memory address/data 10. bias3 input for lcd. remappable peripheral pin 30 input/output. parallel slave port chip select. general purpose i/o pin. ad11/com0/rp33/refo1/re3 ad11 com0 rp33 refo1 re3 97 77 63 i/o o i/o o i/o ttl/dig analog st/dig dig st/dig external memory address/data 11. com0 output for lcd. remappable peripheral pin 33 input/output. reference output clock. general purpose i/o pin. ad12/com1/rp32/re4 ad12 com1 rp32 re4 95 76 62 i/o o i/o i/o ttl/dig analog st/dig st/dig external memory address/data 12. com1 output for lcd. remappable peripheral pin 32 input/output. general purpose i/o pin. ad13/com2/rp37/re5 ad13 com2 rp37 re5 94 75 61 i/o o i/o i/o ttl/dig analog st/dig st/dig external memory address/data 13. com2 output for lcd. remappable peripheral pin 37 input/output. general purpose i/o pin. ad14/com3/rp34/re6 ad14 com3 rp34 re6 93 74 60 i/o o i/o i/o ttl/dig analog st/dig st/dig external memory address/data 14. com3 output for lcd. remappable peripheral pin 34 input/output. general purpose i/o pin. ad15/lcdbias0/rp31/re7 ad15 lcdbias0 rp31 re7 92 73 59 i/o i i/o i/o ttl/dig analog st/dig st/dig external memory address/data 15. bias0 input for lcd. remappable peripheral pin 31 input/output. general purpose i/o pin. table 1-4: pic18f97j94 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 100 80 64 legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) i2c = i 2 c?/smbus
? 2012 microchip technology inc. ds30575a-page 23 pic18f97j94 family seg20/an7/ctmui/c2inb/rp36/ rf2 seg20 an7 ctmui c2inb rp36 rf2 23 18 16 o i o i i/o i/o analog analog ? analog st/dig st/dig seg20 output for lcd. analog input 7. ctmu pulse generator charger for the c2inb comparator input. comparator 2 input b. remappable peripheral pin 36 input/output. general purpose i/o pin. d-/rf3 d- rf3 22 17 15 i/o i ? st usb bus minus line input/output. general purpose input pin. d+/rf4 d+ rf4 20 16 14 i/o i ? st usb bus plus line input/output. general purpose input pin. seg23/cv ref /an10/c1inb/ rp35/rf5 seg23 cv ref an10 c1inb rp35 rf5 19 15 13 o o i i i/o i/o analog analog analog analog st/dig st/dig seg23 output for lcd. comparator reference voltage output. analog input 10. comparator 1 input b. remappable peripheral pin 35 input/output. general purpose i/o pin. seg24/an11/c1ina/rp40/rf6 seg24 an11 c1ina rp40 rf6 18 14 12 o i i i/o i/o analog analog analog st/dig st/dig seg24 output for lcd. analog input 11. comparator 1 input a. remappable peripheral pin 40 input/output. general purpose i/o pin. seg25/an5/rp38/rf7 seg25 an5 rp38 rf7 17 13 11 o i i/o i/o analog analog st/dig st/dig seg25 output for lcd. analog input 5. remappable peripheral pin 38 input/output. general purpose i/o pin. table 1-4: pic18f97j94 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 100 80 64 legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) i2c = i 2 c?/smbus
pic18f97j94 family ds30575a-page 24 ? 2012 microchip technology inc. com4/seg28/an8/rp46/rg0 com4 seg28 an8 rp46 rg0 6 5 3 o o i i/o i/o analog analog analog st/dig st/dig com4 output for lcd. seg28 output for lcd. analog input 8. remappable peripheral pin 46 input/output. general purpose i/o pin. com5/seg29/an19/rp39/rg1 com5 seg29 an19 rp39 rg1 7 6 4 o o i i/o i/o analog analog analog st/dig st/dig com5 output for lcd. seg29 output for lcd. analog input 19. remappable peripheral pin 39 input/output. general purpose i/o pin. com6/seg30/an18/c3ina/rp42/ rg2 com6 seg30 an18 c3ina rp42 rg2 8 7 5 o o i i i/o i/o analog analog analog analog st/dig st/dig com6 output for lcd. seg30 output for lcd. analog input 18. comparator 3 input a. remappable peripheral pin 42 input/output. general purpose i/o pin. com7/seg31/an17/c3inb/rp43/ rg3 com7 seg31 an17 c3inb rp43 rg3 9 8 6 o o i i i/o i/o analog analog analog analog st/dig st/dig com7 output for lcd. seg31 output for lcd. analog input 17. comparator 3 input b. remappable peripheral pin 43 input/output. general purpose i/o pin. seg26/an16/c3inc/rp44/rtcc/ rg4 seg26 an16 c3inc rp44 rtcc rg4 12 10 8 o i i i/o o i/o analog analog analog st/dig ? st/dig seg26 output for lcd. analog input 16. comparator 3 input c. remappable peripheral pin 44 input/output. rtcc output. general purpose i/o pin. rg6 89 i/o st/dig general purpose i/o pin. rg7 96 i/o st/dig general purpose i/o pin. table 1-4: pic18f97j94 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 100 80 64 legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) i2c = i 2 c?/smbus
? 2012 microchip technology inc. ds30575a-page 25 pic18f97j94 family a16/seg47/an23/rh0 a16 seg47 an23 rh0 99 79 o o i i/o dig analog analog st/dig external memory address 16. seg47 output for lcd. analog input 23. general purpose i/o pin. a17/seg46/an22/rh1 a17 seg46 an22 rh1 100 80 o o i i/o dig analog analog st/dig external memory address 17. seg46 output for lcd. analog input 22. general purpose i/o pin. a18/seg45/an21/rh2 a18 seg45 an21 rh2 1 1 o o i i/o dig analog analog st/dig external memory address 18. seg45 output for lcd. analog input 21. general purpose i/o pin. a19/seg44/an20/rh3 a19 seg44 an20 rh3 2 2 o o i i/o dig analog analog st/dig external memory address 19. seg44 output for lcd. analog input 20. general purpose i/o pin. seg40/an12/c2inc/rh4 seg40 an12 c2inc rh4 27 22 o i i i/o analog analog analog st/dig seg40 output for lcd. analog input12. comparator 2 input c. general purpose i/o pin. seg41/an13/c2ind/rh5 seg41 an13 c2ind rh5 26 21 o i i i/o analog analog analog st/dig seg41 output for lcd. analog input 13. comparator 2 input d. general purpose i/o pin. seg42/an14/c1inc/rh6 seg42 an14 c1inc rh6 25 20 o i i i/o analog analog analog st/dig seg42 output for lcd. analog input 14. comparator 1 input c. general purpose i/o pin. seg43/an15/rh7 seg43 an15 rh7 24 19 o i i/o analog analog st/dig seg43 output for lcd. analog input 15. general purpose i/o pin. table 1-4: pic18f97j94 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 100 80 64 legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) i2c = i 2 c?/smbus
pic18f97j94 family ds30575a-page 26 ? 2012 microchip technology inc. ale/seg32/rj0 ale seg32 rj0 77 62 o o i/o dig analog st/dig external memory address latch enable. seg32 output for lcd. general purpose i/o pin. oe /seg33/rj1 oe seg33 rj1 76 61 o o i/o dig analog st/dig external memory output enable. seg33 output for lcd. general purpose i/o pin. wrl /seg34/rj2 w r l seg34 rj2 75 60 o o i/o dig analog st/dig external memory write low control. seg34 output for lcd. general purpose i/o pin. wrh /seg35/rj3 w r h seg35 rj3 74 59 o o i/o dig analog st/dig external memory write high control. seg35 output for lcd. general purpose i/o pin. ba0/seg39/rj4 ba0 seg39 rj4 49 39 o o i/o dig analog st/dig external memory byte address 0 control seg39 output for lcd. general purpose i/o pin. ce /seg38/rj5 ce seg38 rj5 50 40 o o i/o dig analog st/dig external memory chip enable control. seg38 output for lcd. general purpose i/o pin. lb /seg37/rj6 lb seg37 rj6 51 41 o o i/o dig analog st/dig external memory low byte control. seg37 output for lcd. general purpose i/o pin. ub /seg36/rj7 ub seg36 rj7 52 42 o o i/o dig analog st/dig external memory high byte control. seg36 output for lcd. general purpose i/o pin. table 1-4: pic18f97j94 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 100 80 64 legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) i2c = i 2 c?/smbus
? 2012 microchip technology inc. ds30575a-page 27 pic18f97j94 family seg56/rk0 seg56 rk0 46 o i/o analog st/dig seg56 output for lcd. general purpose i/o pin. seg57/rk1 seg57 rk2 55 o i/o analog st/dig seg57 output for lcd. general purpose i/o pin. seg58/rk2 seg58 rk2 60 o i/o analog st/dig seg58 output for lcd. general purpose i/o pin. seg59/rk3 seg59 rk3 63 o i/o analog st/dig seg59 output for lcd. general purpose i/o pin. seg60/rk4 seg60 rk4 66 o i/o analog st/dig seg60 output for lcd. general purpose i/o pin. seg61/rk5 seg61 rk5 71 o i/o analog st/dig seg61 output for lcd. general purpose i/o pin. seg62/rk6 seg62 rk6 80 o i/o analog st/dig seg62 output for lcd. general purpose i/o pin. seg63/rk7 seg63 rk7 85 o i/o analog st/dig seg63 output for lcd. general purpose i/o pin. table 1-4: pic18f97j94 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 100 80 64 legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) i2c = i 2 c?/smbus
pic18f97j94 family ds30575a-page 28 ? 2012 microchip technology inc. seg48/rl0 seg48 rl0 91 o i/o analog st/dig seg48 output for lcd. general purpose i/o pin. seg49/rl1 seg49 rl1 10 o i/o analog st/dig seg49 output for lcd. general purpose i/o pin. seg50/rl2 seg50 rl3 13 o i/o analog st/dig seg50 output for lcd. general purpose i/o pin. seg51/rl3 seg51 rl4 16 o i/o analog st/dig seg51 output for lcd. general purpose i/o pin. seg52/rl4 seg52 rl4 21 o i/o analog st/dig seg52 output for lcd. general purpose i/o pin. seg53/rl5 seg53 rl5 30 o i/o analog st/dig seg53 output for lcd. general purpose i/o pin. seg54/rl6 seg54 rl6 38 o i/o analog st/dig seg54 output for lcd. general purpose i/o pin. seg55/rl7 seg55 rl7 41 o i/o analog st/dig seg55 output for lcd. general purpose i/o pin. table 1-4: pic18f97j94 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 100 80 64 legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) i2c = i 2 c?/smbus
? 2012 microchip technology inc. ds30575a-page 29 pic18f97j94 family v dd 1 v dd 2 v dd 3 v dd 4 5 40 59 88 32 48 71 26 38 57 p ? positive supply for logic and i/o pins. v ss 1 v ss 2 v ss 3 v ss 4 vss5 14 35 39 64 87 11 31 51 70 9 25 41 56 p ? ground reference for logic and i/o pins. a vdd 31 25 19 p ? positive supply for analog modules. a vss 32 26 20 p ? ground reference for analog modules. v ddcore /v cap v ddcore v cap 15 12 10 p p ? ? core logic power or external filter capacitor connection. external filter capacitor connection (regulator enabled/disabled). v bat 29 24 18 p ? v usb 3 v 3 28 23 17 p ? usb voltage input pin. table 1-4: pic18f97j94 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 100 80 64 legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) i2c = i 2 c?/smbus
pic18f97j94 family ds30575a-page 30 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 31 pic18f97j94 family 2.0 guidelines for getting started with pic18fj microcontrollers 2.1 basic connection requirements getting started with the pic18f97j94 family of 8-bit microcontrollers requires attention to a minimal set of device pin connection before proceeding with development. the following pins must always be connected: ?all v dd and v ss pins (see section 2.2 ?power supply pins? ) ?all av dd and av ss pins, regardless of whether or not the analog device features are used (see section 2.2 ?power supply pins? ) ?mclr pin (see section 2.3 ?master clear (mclr) pin? ) these pins must also be connected if they are being used in the end application: ? pgc/pgd pins used for in-circuit serial programming? (icsp?) and debugging purposes (see section 2.5 ?icsp pins? ) ? osc1 and osc2 pins when an external oscillator source is used (see section 2.6 ?external oscillator pins? ) additionally, the following pins may be required: ?v ref +/v ref - pins are used when external voltage reference for analog modules is implemented the minimum mandatory connections are shown in figure 2-1 . figure 2-1: recommended minimum connections note: the av dd and av ss pins must always be connected, regardless of whether any of the analog modules are being used. pic18fxxjxx v dd v ss v dd v ss v ss v dd av dd av ss v dd v ss c1 r1 v dd mclr v cap /v ddcore r2 c7 c2 (2) c3 (2) c4 (2) c5 (2) c6 (2) key (all values are recommendations): c1 through c6: 0.1 ? f, 20v ceramic c7: 10 ? f, 6.3v or greater, tantalum or ceramic r1: 10 k ? r2: 100 ? to 470 ? note 1: see section 2.4 ?core voltage regulator (v cap /v ddcore )? for explanation of v cap /v ddcore connections. 2: the example shown is for a pic18f device with five v dd /v ss and av dd /av ss pairs. other devices may have more or less pairs; adjust the number of decoupling capacitors appropriately. (1)
pic18f97j94 family ds30575a-page 32 ? 2012 microchip technology inc. 2.2 power supply pins 2.2.1 decoupling capacitors the use of decoupling capacitors on every pair of power supply pins, such as v dd , v ss , av dd and av ss , is required. consider the following criteria when using decoupling capacitors: ? value and type of capacitor: a 0.1 ? f (100 nf), 10-20v capacitor is recommended. the capacitor should be a low-esr device, with a resonance frequency in the range of 200 mhz and higher. ceramic capacitors are recommended. ? placement on the printed circuit board: the decoupling capacitors should be placed as close to the pins as possible. it is recommended to place the capacitors on the same side of the board as the device. if space is constricted, the capacitor can be placed on another layer on the pcb using a via; however, ensure that the trace length from the pin to the capacitor is no greater than 0.25 inch (6 mm). ? handling high-frequency noise: if the board is experiencing high-frequency noise (upward of tens of mhz), add a second ceramic type capaci- tor in parallel to the above described decoupling capacitor. the value of the second capacitor can be in the range of 0.01 ? f to 0.001 ? f. place this second capacitor next to each primary decoupling capacitor. in high-speed circuit designs, consider implementing a decade pair of capacitances as close to the power and ground pins as possible (e.g., 0.1 ? f in parallel with 0.001 ? f). ? maximizing performance: on the board layout from the power supply circuit, run the power and return traces to the decoupling capacitors first, and then to the device pins. this ensures that the decoupling capacitors are first in the power chain. equally important is to keep the trace length between the capacitor and the power pins to a minimum, thereby reducing pcb trace inductance. 2.2.2 tank capacitors on boards with power traces running longer than six inches in length, it is suggested to use a tank capac- itor for integrated circuits, including microcontrollers, to supply a local power source. the value of the tank capacitor should be determined based on the trace resistance that connects the power supply source to the device, and the maximum current drawn by the device in the application. in other words, select the tank capacitor so that it meets the acceptable voltage sag at the device. typical values range from 4.7 ? f to 47 ? f. 2.3 master clear (mclr ) pin the mclr pin provides two specific device functions: device reset, and device programming and debugging. if programming and debugging are not required in the end application, a direct connection to v dd may be all that is required. the addition of other components, to help increase the application?s resistance to spurious resets from voltage sags, may be beneficial. a typical configuration is shown in figure 2-1 . other circuit designs may be implemented, depending on the application?s requirements. during programming and debugging, the resistance and capacitance that can be added to the pin must be considered. device programmers and debuggers drive the mclr pin. consequently, specific voltage levels (v ih and v il ) and fast signal transitions must not be adversely affected. therefore, specific values of r1 and c1 will need to be adjusted based on the application and pcb requirements. for example, it is recommended that the capacitor, c1, be isolated from the mclr pin during programming and debugging operations by using a jumper ( figure 2-2 ). the jumper is replaced for normal run-time operations. any components associated with the mclr pin should be placed within 0.25 inch (6 mm) of the pin. figure 2-2: example of mclr pin connections note 1: r1 ?? 10 k ? is recommended. a suggested starting value is 10 k ? . ensure that the mclr pin v ih and v il specifications are met. 2: r2 ?? 470 ? will limit any current flowing into mclr from the external capacitor, c, in the event of mclr pin breakdown, due to electrostatic discharge (esd) or electrical overstress (eos). ensure that the mclr pin v ih and v il specifications are met. c1 r2 r1 v dd mclr pic18fxxjxx jp
? 2012 microchip technology inc. ds30575a-page 33 pic18f97j94 family 2.4 core voltage regulator (v cap /v ddcore ) a low-esr (< 5 ? ) capacitor is required on the v cap pin to stabilize the output voltage of the on-chip voltage regulator. the v cap pin must not be connected to v dd and must use a capacitor of 10 f connected to ground. the type can be ceramic or tantalum. suitable examples of capacitors are shown in table 2-1 . capacitors with equivalent specification can be used. designers may use figure 2-3 to evaluate esr equivalence of candidate devices. it is recommended that the trace length not exceed 0.25 inch (6 mm). refer to section 31.0 ?electrical characteristics? for additional information. figure 2-3: frequency vs. esr performance for suggested v cap . 10 1 0.1 0.01 0.001 0.01 0.1 1 10 100 1000 10,000 frequency (mhz) esr ( ? ) note: typical data measurement at 25c, 0v dc bias. table 2-1: suitable capacitor equivalents make part # nominal capacitance base tolerance rated voltage temp. range tdk c3216x7r1c106k 10 f 10% 16v -55 to 125oc tdk c3216x5r1c106k 10 f 10% 16v -55 to 85oc panasonic ecj-3yx1c106k 10 f 10% 16v -55 to 125oc panasonic ecj-4yb1c106k 10 f 10% 16v -55 to 85oc murata grm32dr71c106ka01l 10 f 10% 16v -55 to 125oc murata grm31cr61c106kc31l 10 f 10% 16v -55 to 85oc
pic18f97j94 family ds30575a-page 34 ? 2012 microchip technology inc. 2.4.1 considerations for ceramic capacitors in recent years, large value, low-voltage, surface-mount ceramic capacitors have become very cost effective in sizes up to a few tens of microfarad. the low-esr, small physical size and other properties make ceramic capacitors very attractive in many types of applications. ceramic capacitors are suitable for use with the v ddcore voltage regulator of this microcontroller. however, some care is needed in selecting the capac- itor to ensure that it maintains sufficient capacitance over the intended operating range of the application. typical low-cost, 10 f ceramic capacitors are available in x5r, x7r and y5v dielectric ratings (other types are also available, but are less common). the initial toler- ance specifications for these types of capacitors are often specified as 10% to 20% (x5r and x7r), or -20%/+80% (y5v). however, the effective capacitance that these capacitors provide in an application circuit will also vary based on additional factors, such as the applied dc bias voltage and the temperature. the total in-circuit tolerance is, therefore, much wider than the initial tolerance specification. the x5r and x7r capacitors typically exhibit satisfac- tory temperature stability (ex: 15% over a wide temperature range, but consult the manufacturer?s data sheets for exact specifications). however, y5v capaci- tors typically have extreme temperature tolerance specifications of +22%/-82%. due to the extreme temperature tolerance, a 10 f nominal rated y5v type capacitor may not deliver enough total capacitance to meet minimum v ddcore voltage regulator stability and transient response requirements. therefore, y5v capacitors are not recommended for use with the v ddcore regulator if the application must operate over a wide temperature range. in addition to temperature tolerance, the effective capacitance of large value ceramic capacitors can vary substantially, based on the amount of dc voltage applied to the capacitor. this effect can be very signifi- cant, but is often overlooked or is not always documented. a typical dc bias voltage vs. capacitance graph for x7r type and y5v type capacitors is shown in figure 2-4 . figure 2-4: dc bias voltage vs. capacitance characteristics when selecting a ceramic capacitor to be used with the v ddcore voltage regulator, it is suggested to select a high-voltage rating, so that the operating voltage is a small percentage of the maximum rated capacitor volt- age. for example, choose a ceramic capacitor rated at 16v for the 2.5v v ddcore voltage. suggested capacitors are shown in table 2-1 . 2.5 icsp pins the pgc and pgd pins are used for in-circuit serial programming? (icsp?) and debugging purposes. it is recommended to keep the trace length between the icsp connector and the icsp pins on the device as short as possible. if the icsp connector is expected to experience an esd event, a series resistor is recom- mended, with the value in the range of a few tens of ohms, not to exceed 100 ? . pull-up resistors, series diodes, and capacitors on the pgc and pgd pins are not recommended as they will interfere with the programmer/debugger communica- tions to the device. if such discrete components are an application requirement, they should be removed from the circuit during programming and debugging. alter- natively, refer to the ac/dc characteristics and timing requirements information in the respective device flash programming specification for information on capacitive loading limits, and pin input voltage high (v ih ) and input low (v il ) requirements. for device emulation, ensure that the ?communication channel select? (i.e., pgcx/pgdx pins), programmed into the device, matches the physical connections for the icsp to the microchip debugger/emulator tool. for more information on available microchip development tools connection requirements, refer to section 30.0 ?development support? . -80 -70 -60 -50 -40 -30 -20 -10 0 10 5 1011121314151617 dc bias voltage (vdc) capacitance change (%) 01234 67 89 16v capacitor 10v capacitor 6.3v capacitor
? 2012 microchip technology inc. ds30575a-page 35 pic18f97j94 family 2.6 external oscillator pins many microcontrollers have options for at least two oscillators: a high-frequency primary oscillator and a low-frequency secondary oscillator (refer to section 3.0 ?oscillator configurations? for details). the oscillator circuit should be placed on the same side of the board as the device. place the oscillator circuit close to the respective oscillator pins with no more than 0.5 inch (12 mm) between the circuit components and the pins. the load capacitors should be placed next to the oscillator itself, on the same side of the board. use a grounded copper pour around the oscillator cir- cuit to isolate it from surrounding circuits. the grounded copper pour should be routed directly to the mcu ground. do not run any signal traces or power traces inside the ground pour. also, if using a two-sided board, avoid any traces on the other side of the board where the crystal is placed. layout suggestions are shown in figure 2-5 . in-line packages may be handled with a single-sided layout that completely encompasses the oscillator pins. with fine-pitch packages, it is not always possible to com- pletely surround the pins and components. a suitable solution is to tie the broken guard sections to a mirrored ground layer. in all cases, the guard trace(s) must be returned to ground. in planning the application?s routing and i/o assign- ments, ensure that adjacent port pins, and other signals in close proximity to the oscillator, are benign (i.e., free of high frequencies, short rise and fall times, and other similar noise). for additional information and design guidance on oscillator circuits, please refer to these microchip application notes, available at the corporate web site (www.microchip.com): ? an826, ? crystal oscillator basics and crystal selection for rfpic? and picmicro ? devices? ? an849, ?basic picmicro ? oscillator design? ? an943, ?practical picmicro ? oscillator analysis and design? ? an949, ?making your oscillator work? 2.7 unused i/os unused i/o pins should be configured as outputs and driven to a logic low state. alternatively, connect a 1 k ? to 10 k ? resistor to v ss on unused pins and drive the output to logic low. figure 2-5: suggested placement of the oscillator circuit gnd ` ` ` osc1 osc2 t1oso t1os i copper pour primary oscillator crystal timer1 oscillator crystal device pins primary oscillator c1 c2 t1 oscillator: c1 t1 oscillator: c2 (tied to ground) single-sided and in-line layouts: fine-pitch (dual-sided) layouts: gnd osc2 osc1 bottom layer copper pour oscillator crystal top layer copper pour c2 c1 device pins (tied to ground) (tied to ground)
pic18f97j94 family ds30575a-page 36 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 37 pic18f97j94 family 3.0 oscillator configurations this section describes the pic18f oscillator system and its operation. the pic18f oscillator system has the following modules and features: ? a total of four external and internal oscillator options as clock sources, providing up to 11 different clock modes ? an on-chip usb pll block to provide a stable 48 mhz clock for the usb module, as well as a range of frequency options for the system clock ? software-controllable switching between various clock sources ? software-controllable postscaler for selective clocking of cpu for system power savings ? a fail-safe clock monitor (fscm) that detects clock failure and permits safe application recovery or shutdown ? a separate and independently configurable system clock output for synchronizing external hardware a simplified diagram of the oscillator system is shown in figure 3-1 . figure 3-1: pic18f genera l system clock diagram pic18f97j94 family secondary oscillator soscen enable oscillator sosco sosci clock source option for other modules osc1 osc2 primary oscillator ms, hs, ec peripherals osccon3<2:0> wdt, pwrt 8 mhz frcdiv 31 khz (nominal) frc oscillator sosc lprc clock control logic fail-safe clock monitor frc (nominal) 8 mhz 4 mhz pll & div plldiv<3:0> cpdiv<1:0> 48 mhz usb clock usb pll reference clock generator refo frc active clock control reference from usb d+/d- refoxcon2<7:0> lprc oscillator mspll, hspll, ecpll, frcpll postscaler frcdiv 16 500 khz tuning
pic18f97j94 family ds30575a-page 38 ? 2012 microchip technology inc. 3.1 cpu clocking scheme the system clock source can be provided by one of four sources: ? primary oscillator (posc) on the osc1 and osc2 pins ? secondary oscillator (sosc) on the sosci and sosco pins ? fast internal rc (frc) oscillator ? low-power internal rc (lprc) oscillator the primary oscillator and frc sources have the option of using the internal usb pll block, which generates both the usb module clock and a separate system clock from the 96 mhz pll. refer to section 3.8.1 ?oscilla- tor modes and usb operation? for additional information. the internal frc provides an 8 mhz clock source. it can optionally be reduced by the programmable clock divider to provide a range of system clock frequencies. the selected clock source generates the processor and peripheral clock sources. the processor clock source is divided by four to produce the internal instruc- tion cycle clock, f cy . in this document, the instruction cycle clock is also denoted by f osc /4. the internal instruction cycle clock, f osc /4, can be provided on the osc2 i/o pin for some operating modes of the primary oscillator. the timing diagram in figure 3-2 shows the relationship between the processor clock source and instruction execution. figure 3-2: clock or instruction cycle timing f osc pc f cy pc pc + 2 pc + 4 fetch inst (pc) execute inst (pc ? 2) fetch inst (pc + 2) execute inst (pc) fetch inst (pc + 4) execute inst (pc + 2) t cy
? 2012 microchip technology inc. ds30575a-page 39 pic18f97j94 family 3.2 oscillator configuration the oscillator source (and operating mode) that is used at a device power-on reset (por) event is selected using configuration bit settings. the oscillator configu- ration bit settings are in the configuration registers located in the program memory (refer to section 28.1 ?configuration bits? for more information). the primary oscillator configuration bits, poscmd<1:0> (config3l<1:0>), and oscillator configuration bits, fosc<2:0> (config2l<2:0>), select the oscillator source that is used at a por. the frc oscillator with postscaler (frcdiv) is the default (unprogrammed) selection. the secondary oscillator, or one of the inter- nal oscillators, may be chosen by programming these bit locations. the configuration bits allow users to choose between 11 different clock modes, as shown in ta b l e 3 - 1 . table 3-1: configuration bit va lues for clock selection oscillator mode oscillator source poscmd<1:0> fosc<2:0> notes fast rc oscillator with postscaler (frcdiv) internal 11 111 1 , 2 fast rc oscillator divided by 16 (frc500khz) internal 11 110 1 low-power rc oscillator (lprc) internal 11 101 1 secondary (timer1) oscillator (sosc) secondary 11 100 1 primary oscillator (hs) with pll module (hspll) primary 10 011 primary oscillator (ms) with pll module (mspll) primary 01 011 primary oscillator (ec) with pll module (ecpll) primary 00 011 primary oscillator (hs) primary 10 010 primary oscillator (ms) primary 01 010 primary oscillator (ec) primary 00 010 fast rc oscillator with pll module (frcpll) internal 11 001 1 fast rc oscillator (frc) internal 11 000 1 note 1: osc2 pin function is determined by the clkoen configuration bit. 2: default oscillator mode for an unprogrammed (erased) device.
pic18f97j94 family ds30575a-page 40 ? 2012 microchip technology inc. 3.2.1 clock switching mode configuration bits the fscmx configuration bits (config3l<5:4>) are used to jointly configure device clock switching and the fail-safe clock monitor (fscm). clock switching is enabled only when fscm1 is programmed (? 0 ?). the fscm is enabled only when fscm<1:0> are both programmed (? 00 ?). 3.2.2 osc1 and osc2 pin functions in non-crystal modes when the primary oscillator on osc1 and osc2 is not configured as the clock source (poscmd<1:0> = 11 ), the osc1 pin is automatically reconfigured as a digital i/o. in this configuration, as well as when the primary oscillator is configured for ec mode (poscmd<1:0> = 00 ), the osc2 pin can also be configured as a digital i/o by programming the clkoen configuration bit (config2l<5>). when clkoen is unprogrammed (? 1 ?), a f osc /4 clock output is available on osc2 for testing or synchroniza- tion purposes. with clkoen programmed (? 0 ?), the osc2 pin becomes a general purpose i/o pin. in both of these configurations, the feedback device between osc1 and osc2 is turned off to save current. 3.3 control registers the operation of the oscillator is controlled by six special function registers (sfrs): ? osccon ? osccon2 ? osccon3 ? osccon4 ? actcon ? osctune 3.3.1 oscillator control register (osccon) the osccon register ( register 3-1 ) is the main con- trol register for the oscillator. it controls clock source switching and allows the monitoring of clock sources. the coscx (osccon<6:4>) status bits are read-only bits that indicate the current oscillator source the device is operating from. the coscx bits default to the internal fast rc oscillator with postscaler (frcdiv), configured for 4 mhz, on a power-on reset (por) and master clear reset (mclr ). a clock switch will automatically be performed to the new oscillator source selected by the foscx configuration bits (config2l<2:0>). the coscx bits will change to indi- cate the new oscillator source at the end of a clock switch operation. the noscx status bits select the clock source for the next clock switch operation. on por and mclr s, these bits automatically select the oscillator source defined by the foscx configuration bits. these bits can be modified by software. setting the clklock bit (osccon2<7>) prevents clock switching if the fscm1 configuration bit is set. if the fscm1 bit is clear, the clklock bit state is ignored and clock switching can occur. the iolock bit (osccon2<6>) is used to unlock the peripheral pin select (pps) feature; it has no function in the system clock?s operation. the lock status bit (osccon2<5>) is read-only and indicates the status of the pll circuit. it is set when the pll achieves a frequency lock and is reset when a valid clock switching sequence is initiated. it reads as ? 0 ? whenever the pll is not used as part of the current clock source. the cf status bit (osccon2<3>) is a readable/clearable status bit that indicates a clock failure; it is reset whenever a valid clock switch occurs. the poscen bit (osccon2<2 >) is used to control the operation of the primary oscillator in sleep mode. setting this bit bypasses the normal automatic shutdown of the oscillator whenever sleep mode is invoked. the secondary oscillator can be turned on by a variety of options: ? soscgo ? osccon2<1> ? soscsel ? config2l<3> ? fosc<2:0> ? config2l<2:0> ? dswdtosc ? config8h<1> ? rtcen ? rtccon1<7> ? soscen ? t1con<3>, t3con<3> or t5con<3> the actcon register ( register 3-10 ) controls the active clock tuning features.
? 2012 microchip technology inc. ds30575a-page 41 pic18f97j94 family register 3-1: osccon: osci llator control register r/w-0 r-x r-x r-x u-0 r/w-x r/w-x r/w-x idlen cosc2 cosc1 cosc0 ? nosc2 nosc1 nosc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 idlen: idle enable bit 1 = sleep instruction invokes idle mode 0 = sleep instruction invokes sleep mode bit 6-4 cosc<2:0>: current oscillator selection bits (read-only) 000 = fast rc oscillator (frc) 001 = fast rc oscillator (frc), divided by n, with pll module 010 = primary oscillator (ms, hs, ec) 011 = primary oscillator (ms, hs, ec) with pll module 100 = secondary oscillator (sosc) 101 = low-power rc oscillator (lprc) 110 = fast rc oscillator (frc) divided by 16 (500 khz) 111 = fast rc oscillator (frc) divided by n bit 3 unimplemented: read as ? 0 ? bit 2-0 nosc<2:0>: new oscillator selection bits 000 = fast rc oscillator (frc) 001 = fast rc oscillator (frc), divided by n, with pll module 010 = primary oscillator (ms, hs, ec) 011 = primary oscillator (ms, hs, ec) with pll module 100 = secondary oscillator (sosc) 101 = low-power rc oscillator (lprc) 110 = fast rc oscillator (frc) divided by 16 (500 khz) 111 = fast rc oscillator (frc) divided by n
pic18f97j94 family ds30575a-page 42 ? 2012 microchip technology inc. register 3-2: osccon2: osci llator control register 2 r/w-0 r/w-0 r-0 u-0 r/c-0 r/w-0 r/w-0 u-0 clklock ( 2 ) iolock ( 1 ) lock ?cfposcensoscgo ? bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 clklock: clock lock enabled bit ( 2 ) 1 = clock and pll selection are locked and may not be modified 0 = clock and pll selection are not locked, configurations may be modified bit 6 iolock: i/o lock enable bit ( 1 ) 1 = i/o lock is active (if iol1way (config5h<0> = 1) , the bit cannot be cleared, once it is set, except on a device reset.) 0 = i/o lock is not active bit 5 lock: pll lock status bit (read-only) 1 = indicates that pll module is in lock or pll start-up timer is satisfied 0 = indicates that pll module is out of lock, pll start-up timer is in progress or pll is disabled bit 4 unimplemented: read as ? 0 ? bit 3 cf: clock fail detect bit (readable/clearable by application) 1 = fscm has detected a clock failure 0 = fscm has not detected a clock failure bit 2 poscen: primary oscillator (posc) enable bit 1 = enables primary oscillator in sleep mode 0 = disables primary oscillator in sleep mode bit 1 soscgo: 32 khz secondary (lp) oscillator enable bit 1 = enables secondary oscillator independent of other sosc enable requests; provides a way to keep the sosc running even when not actively used by the system 0 = disables secondary oscillator; the sosc will be enabled if directly requested by the system. reset on por or bor only. bit 0 unimplemented: read as ? 0 ? note 1: the iolock bit cannot be cleared once it has been set, provided that the iol1way (config5h<0>) = 1 . 2: if the user wants to change the clock source, ensure that the fscm<1:0> bits (config3l<5:4>) are set appropriately.
? 2012 microchip technology inc. ds30575a-page 43 pic18f97j94 family 3.3.2 osccon3 ? clock divider register (ircf<2:0> bits) the ircfx bits (osccon3<2:0>) select the postscaler option for the frc oscillator output, allowing users to choose a lower clock frequency than the nominal 8 mhz. this option is described in more detail in section 3.10.2 ?frc postscaler mode (frcdiv)? and section 3.10.3 ?frc oscillator with pll mode (frcpll)? . register 3-3: osccon3: osci llator control register 3 register 3-4: osccon4: osci llator control register 4 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-1 ? ? ? ? ?ircf2 ( 1 ) ircf1 ( 1 ) ircf0 ( 1 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-3 unimplemented: read as ? 0 ? bit 2-0 ircf<2:0>: reference clock divider bits ( 1 ) 000 = frc divide-by-1 001 = frc divide-by-2 (default) 010 = frc divide-by-4 011 = frc divide-by-8 100 = frc divide-by-16 101 = frc divide-by-32 110 = frc divide-by-64 111 = frc divide-by-256 note 1: the default frc divide-by setting on an 8-bit device corresponds to 1 mips operation. r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 u-0 cpdiv1 cpdiv0 pllen ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 cpdiv<1:0>: usb system clock select bits (postscaler select from 64 mhz clock branch) 00 = input clock/1 01 = input clock/2 10 = input clock/4 11 = input clock/8 bit 5 pllen: pll enable bit 1 = pll is enabled even though it is not requested by the cpu; provides ability to ?warm-up? the pll and keep it running to avoid the pll start-up time. this setting will force the pll and associated clock source to stay active in sleep. 0 = pll is disabled; pll will be automatically turned on when src1 is selected, or when refo1 or refo2 is enabled and using the pll clock as its source. in either case, the pll will require a start-up time. bit 4-0 unimplemented: read as ? 0 ?
pic18f97j94 family ds30575a-page 44 ? 2012 microchip technology inc. 3.3.3 oscillator tuning register (osctune) the frc oscillator tuning register ( register 3-5 ) allows the user to fine-tune the frc oscillator. refer to the data sheet of the specific device for further information regarding the frc oscillator tuning. the tuning response of the frc oscillator may not be monotonic or linear; the next closest frequency may be offset by a number of steps. it is recommended that users try multiple values of osctune to find the closest value to the desired frequency. register 3-5: osctune: frc oscillator tuning register u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? tun5 tun4 tun3 tun2 tun1 tun0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at all resets ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-0 tun<5:0>: frc oscillator tuning bits 011111 = maximum frequency deviation 011110 = . . . 000001 = 000000 = center frequency; oscillator is running at factory calibrated frequency 111111 = . . . 100001 = 100000 = minimum frequency deviation
? 2012 microchip technology inc. ds30575a-page 45 pic18f97j94 family 3.4 reference clock output control module the pic18f97j94 family has two reference clock output (refo) modules. each of the reference clock output modules provides the user with the ability to send out a programmed output clock onto the refo1or refo2 pins. 3.4.1 reference clock source the module provides the ability to select one of the following clock sources: ? primary crystal oscillator (posc) ? secondary crystal oscillator (sosc) ? 32.768 khz internal oscillator (intosc) ? fast internal oscillator (frc) it includes a programmable clock divider with ratios ranging from 1:1 to 1:65534. when the clock source is a crystal or internal oscillator, the rslp bit can be set to continue refo operation while the device is in sleep mode. 3.4.2 clock synchronization the reference clock output is enabled only once (on = 1 ). note that the source of the clock and the divider values should be chosen prior to the bit being set to avoid glitches on the refo output. once the on bit is set, its value is synchronized to the reference clock output domain to enable the output. this ensures that no glitches will be seen on the output. similarly, when the on bit is cleared, the output and the associated output enable signals will be synchronized and disabled on the falling edge of the reference clock output. note that with large divider values, this will cause the refo to be enabled for some period after on is cleared. 3.4.3 operation in sleep mode if any clock source, other than the peripheral clock, is used as a base reference (i.e., rosel<3:0> ? 0001 ), the user has the option to configure the behavior of the oscillator in sleep mode. the rslp configuration bit determines if the oscillator will continue to run in sleep. if rslp = 0 , the oscillator will be shut down in sleep (assuming no other consumers are requesting it). if rslp = 1 , the oscillator will continue to run in sleep. the reference clock output is synchronized with the sleep signal to avoid any glitches on its output. 3.4.3.1 module enable signal the refox module may be enabled or disabled using the refoxmd register bit, which holds the refox module in reset, or the on register bit, which does not. 3.4.3.2 registers and bits this module provides the following device registers and/or bits: ? refoxcon ? reference clock output control register ? refoxcon1 ? reference clock output control 1 register ? refoxcon2 ? reference clock output control 2 register ? refoxcon3 ? reference clock output control 3 register in addition, the refoxcon1 module needs to be enabled by clearing the refoxmd disable bit (pmd3<1>). 3.4.3.3 interrupts this module does not generate any interrupts. note: throughout this section, references to register and bit names that may be associ- ated with specific reference clock output modules are referred to generically by the use of ?x? in place of the specific module number. thus, ?refoxcon? might refer to the control register for either refo1 or refo2.
pic18f97j94 family ds30575a-page 46 ? 2012 microchip technology inc. register 3-6: refoxcon: referenc e clock output control register r/w-0 u-0 r/w-0 r/w-0 r/w-0 u-0 hc/r/w-0 hs/hc/r-0 on ?sidl oerslp ( 1 ) ? divsw_en active bit 7 bit 0 legend: hc = hardware clearable bit hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at all resets ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 on: reference clock output enable bit 1 = reference clock module is enabled 0 = reference clock module is disabled bit 6 unimplemented: read as ? 0 ? bit 5 sidl: peripheral stop in idle mode bit 1 = discontinues module operation when device enters idle mode 0 = continues module operation in idle mode bit 4 oe: reference clock output enable bit 1 = reference clock is driven out on refox pin 0 = reference clock is not driven out on refox pin bit 3 rslp: reference clock output run in sleep bit ( 1 ) 1 = reference clock output continues to run in sleep 0 = reference clock output is disabled in sleep bit 2 unimplemented: read as ? 0 ? bit 1 divsw_en: clock rodiv switch enabled status bit 1 = clock divider switching currently in progress 0 = clock divider switching has completed bit 0 active: reference clock output request status bit 1 = reference clock request is active (user should not update the rosel and rodiv register fields) 0 = reference clock request is not active (user may update the rosel and rodiv register fields) note 1: this bit has no effect when rosel<3:0> = 0000 / 0001 , as the system clock and peripheral clock are always disabled in sleep mode on pic18 devices.
? 2012 microchip technology inc. ds30575a-page 47 pic18f97j94 family register 3-7: refoxcon1: reference clock output control register 1 u-0 u-0 u-0 u-0 r/w-0 ( 1 ) r/w-0 ( 1 ) r/w-0 ( 1 ) r/w-0 ( 1 ) ? ? ? ? rosel3 rosel2 rosel1 rosel0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at all resets ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: read as ? 0 ? (reserved for additional rosel bits.) bit 3-0 rosel<3:0>: reference clock output source select bits ( 1 ) select one of the various clock sources to be used as the reference clock. 0111 - 1111 = reserved 0110 = pll (4/6/8x or 96 mhz) 0101 =sosc 0100 =lprc 0011 =frc 0010 =posc 0001 = peripheral clock (reference clock reflects any peripheral clock switching) 0000 = system clock (reference clock reflects any device clock switching) when plldiv<3:0> (config2h<3:0>) = 1111 , rosel<3:0> should not be set to ? 0110 ?. note 1: the rosel register field should not be written while the active (refoxcon<0>) bit is ? 1 ?; undefined behavior will result.
pic18f97j94 family ds30575a-page 48 ? 2012 microchip technology inc. register 3-8: refoxcon2: reference clock output control register 2 r/w-0 ( 1 ) r/w-0 ( 1 ) r/w-0 ( 1 ) r/w-0 ( 1 ) r/w-0 ( 1 ) r/w-0 ( 1 ) r/w -0 ( 1 ) r/w -0 ( 1 ) rodiv7 rodiv6 rodiv5 rodiv4 rodiv3 rodiv2 rodiv1 rodiv0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at all resets ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 rodiv<7:0>: reference clock output divider bits ( 1 ) reserved for expansion of rodiv<15>. note 1: the rodiv register field should not be written while the active (refoxcon<0>) bit is ? 1 ?; undefined behavior will result. register 3-9: refoxcon3: reference clock output control register 3 u-0 r/w-0 ( 1 ) r/w-0 ( 1 ) r/w-0 ( 1 ) r/w-0 ( 1 ) r/w-0 ( 1 ) r/w-0 ( 1 ) r/w-0 ( 1 ) ? rodiv14 rodiv13 rodiv12 rodiv11 rodiv10 rodiv9 rodiv8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at all resets ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-0 rodiv<14:8>: reference clock output divider bits ( 1 ) used in conjunction with rodiv<7:0> to specify clock divider frequency. 111111111111111 = refo clock is base clock frequency divided by 65,534 (32,767 * 2) 111111111111110 = refo clock is base clock frequency divided by 65,532 (32,766 * 2) ? ? ? 000000000000011 = refo clock is base clock frequency divided by 6 (3 * 2) 000000000000010 = refo clock is base clock frequency divided by 4 (2 * 2) 000000000000001 = refo clock is base clock frequency divided by 2 (1 * 2) 000000000000000 = refo clock is the same frequency as the base clock (no divider) note 1: the rodiv register field should not be written while the active (refoxcon<0>) bit is ? 1 ?; undefined behavior will result.
? 2012 microchip technology inc. ds30575a-page 49 pic18f97j94 family 3.5 primary oscillator (posc) the primary oscillator is available on the osc1 and osc2 pins of the pic18f family. in general, the pri- mary oscillator can be configured for an external clock input or an external crystal. further details of the primary oscillator operating modes are described in subsequent sections. the primary oscillator has up to 6 operating modes, summarized in ta b l e 3 - 2 . table 3-2: primary oscillator operating modes the poscmdx and foscx configuration bits (config3l<1:0> and config2l<2:0>, respectively) select the operating mode of the primary oscillator. the poscmd<1:0> bits select the particular submode to be used (ms, hs or ec), while the fosc<2:0> bits determine if the oscillator will be used by itself or with the internal pll. the pic18f operates from the primary oscillator whenever the coscx bits (osccon<6:4>) are set to ? 010 ? or ? 011 ?. refer to the ?electrical characteristics? section in the specific device data sheet for further information regarding frequency range for each crystal mode. figure 3-3: crystal or ce ramic resonator operation (ms or hs oscillator mode) oscillator mode description osc2 pin function ec external clock input (0-64 mhz) f osc /4 ecpll external clock input (4-48 mhz), pll enabled f osc /4, note 2 hs 10 mhz-32 mhz crystal note 1 hspll 10 mhz-32 mhz crystal, pll enabled note 2 ms 3.5 mhz-10 mhz crystal note 1 mspll 3.5 mhz-8 mhz crystal, pll enabled note 1 note 1: external crystal is connected to osc1 and osc2 in these modes. 2: available only in devices with special pll blocks (such as the 96 mhz pll); the basic 4x pll block generates clock frequencies beyond the device?s operating range. c1 (3) c2 (3) xtal osc2 r s (1) osc1 r f (2) sleep to internal logic pic18f note 1: a series resistor, rs, may be required for at strip cut crystals. 2: the internal feedback resistor, r f , is typically in the range of 2 to 10 m ?? 3: see section 3.6.5 ?determining the best values for oscillator components? .
pic18f97j94 family ds30575a-page 50 ? 2012 microchip technology inc. 3.5.1 selecting a primary oscillator mode the main difference between the ms and hs modes is the gain of the internal inverter of the oscillator circuit, which allows the different frequency ranges. the ms mode is a medium power, medium frequency mode. hs mode provides the highest oscillator frequencies with a crystal. osc2 provides crystal feedback in both hs and ms oscillator modes. the ec and hs modes that use the pll circuit provide the highest device operating frequencies. the oscilla- tor circuit will consume the most current in these modes because the pll is enabled to multiply the frequency of the oscillator. in general, users should select the oscillator option with the lowest possible gain that still meets their specifica- tions. this will result in lower dynamic currents (i dd ). the frequency range of each oscillator mode is the recommended frequency cutoff, but the selection of a different gain mode is acceptable as long as a thorough validation is performed (voltage, temperature and component variations, such as resistor, capacitor and internal oscillator circuitry). the oscillator feedback circuit is disabled in all ec modes. the osc1 pin is a high-impedance input and can be driven by a cmos driver. if the primary oscillator is configured for an external clock input, the osc2 pin is not required to support the oscillator function. for these modes, the osc2 pin can be used as an additional device i/o pin or a clock out- put pin. when the osc2 pin is used as a clock output pin, the output frequency is f osc /4. 3.6 crystal oscillators and ceramic resonators in ms and hs modes, a crystal or ceramic resonator is connected to the osc1 and osc2 pins to establish oscillation ( figure 3-3 ). the pic18f oscillator design requires the use of a parallel cut crystal. using a series cut crystal may give a frequency out of the crystal manufacturer?s specifications. 3.6.1 oscillator/resonator start-up as the device voltage increases from v ss , the oscillator will start its oscillations. the time required for the oscil- lator to start oscillating depends on many factors, including: ? crystal/resonator frequency ? capacitor values used ? series resistor, if used, and its value and type ? device v dd rise time ? system temperature ? oscillator mode selection of device (selects the gain of the internal oscillator inverter) ? crystal quality ? oscillator circuit layout ? system noise the course of a typical crystal or resonator start-up is shown in figure 3-4 . notice that the time to achieve stable oscillation is not instantaneous. figure 3-4: example oscillator/resonat or start-up characteristics voltage crystal start-up time time device v dd maximum v dd of system 0v v il v ih
? 2012 microchip technology inc. ds30575a-page 51 pic18f97j94 family 3.6.2 primary oscillator start-up from sleep mode the most difficult time for the oscillator to start-up is when waking up from sleep mode. this is because the load capacitors have both partially charged to some quiescent value and phase differential at wake-up is minimal. thus, more time is required to achieve stable oscillation. also remember that low voltage, high tem- peratures and the lower frequency clock modes also impose limitations on loop gain, which in turn, affects start-up. each of the following factors increases the start-up time: ? low-frequency design (with a low gain clock mode) ? quiet environment (such as a battery-operated device) ? operating in a shielded box (away from the noisy rf area) ? low voltage ? high temperature ? wake-up from sleep mode circuit noise, on the other hand, may actually help to ?kick start? the oscillator and help to lower the oscillator start-up time. 3.6.3 oscillator start-up timer in order to ensure that a crystal oscillator (or ceramic resonator) has started and stabilized, an oscillator start-up timer (ost) is provided. the ost is a simple, 10-bit counter that counts 1024 t osc cycles before releasing the oscillator clock to the rest of the system. this time-out period is designated as t ost . the ampli- tude of the oscillator signal must reach the v il and v ih thresholds for the oscillator pins before the ost can begin to count cycles. the t ost interval is required every time the oscillator has to restart (i.e., on por, bor and wake-up from sleep mode). the oscillator start-up timer is applied to the ms and hs modes for the primary oscillator, as well as the secondary oscillator, sosc (see section 3.9 ?secondary oscillator (sosc)? ). 3.6.4 tuning the oscillator circuit since microchip devices have wide operating ranges (frequency, voltage and temperature, depending on the part and version ordered), and external components (crystals, capacitors, etc.) of varying quality and manu- facture, validation of operation needs to be performed to ensure that the component selection will comply with the requirements of the application. there are many factors that go into the selection and arrangement of these external components. depending on the application, these may include any of the following: ? amplifier gain ? desired frequency ? resonant frequency(s) of the crystal ? temperature of operation ? supply voltage range ? start-up time ? stability ? crystal life ? power consumption ? simplification of the circuit ? use of standard components ? component count 3.6.5 determining the best values for oscillator components the best method for selecting components is to apply a little knowledge, and a lot of trial measurement and testing. crystals are usually selected by their parallel resonant frequency only; however, other parameters may be important to your design, such as temperature or frequency tolerance. microchip application note an588, ?picmicro ? microcontroller oscillator design guide? is an excellent reference to learn more about crystal operation and ordering information. the pic18f internal oscillator circuit is a parallel oscillator circuit which requires that a parallel resonant crystal be selected. the load capacitance is usually specified in the 22 pf to 33 pf range. the crystal will oscillate closest to the desired frequency, with a load capacitance in this range. it may be necessary to alter these values, as described later, in order to achieve other benefits. the clock mode is primarily chosen based on the desired frequency of the crystal oscillator. the main dif- ference between the ms and hs oscillator modes is the gain of the internal inverter of the oscillator circuit, which allows the different frequency ranges. in general, use the oscillator option with the lowest possible gain that still meets specifications. this will result in lower dynamic currents (i dd ). the frequency range of each oscillator mode is the recommended frequency cutoff, but the selection of a different gain mode is acceptable as long as a thorough validation is performed (voltage, temperature and component variations, such as resis- tor, capacitor and internal oscillator circuitry). c1 and c2 should also be initially selected based on the load capacitance, as suggested by the crystal manufacturer, and the tables supplied in the device data sheet. the values given in the device data sheet can only be used as a starting point, since the crystal manufacturer, sup- ply voltage, and other factors already mentioned, may cause your circuit to differ from the one used in the factory characterization process. ideally, the capacitance is chosen so that it will oscillate at the highest temperature and the lowest v dd that the circuit will be expected to perform under. high temper- ature and low v dd both have a limiting effect on the
pic18f97j94 family ds30575a-page 52 ? 2012 microchip technology inc. loop gain, such that if the circuit functions at these extremes, the designer can be more assured of proper operation at other temperatures and supply voltage combinations. the output sine wave should not be clipped in the highest gain environment (highest v dd and lowest temperature) and the sine output amplitude should be large enough in the lowest gain environment (lowest v dd and highest temperature) to cover the logic input requirements of the clock, as listed in the device data sheet. osc1 may have specified v il and v ih levels (refer to the specific product data sheet for more information). a method for improving start-up is to use a value of c2 greater than c1. this causes a greater phase shift across the crystal at power-up, which speeds oscillator start-up. besides loading the crystal for proper frequency response, these capacitors can have the effect of lower- ing loop gain if their value is increased. c2 can be selected to affect the overall gain of the circuit. a higher c2 can lower the gain if the crystal is being overdriven (also see discussion on rs). capacitance values that are too high can store and dump too much current through the crystal, so c1 and c2 should not become excessively large. unfortunately, measuring the wattage through a crystal is difficult, but if you do not stray too far from the suggested values, you should not have to be concerned with this. a series resistor, rs, is added to the circuit if after all other external components are selected to satisfaction, and the crystal is still being overdriven. this can be determined by looking at the osc2 pin, which is the driven pin, with an oscilloscope. connecting the probe to the osc1 pin will load the pin too much and nega- tively affect performance. remember that a scope probe adds its own capacitance to the circuit, so this may have to be accounted for in your design (i.e., if the circuit worked best with a c2 of 22 pf and the scope probe was 10 pf, a 33 pf capacitor may actually be called for). the output signal should not be clipping or flattened. overdriving the crystal can also lead to the circuit jumping to a higher harmonic level, or even, crystal damage. the osc2 signal should be a clean sine wave that easily spans the input minimum and maximum of the clock input pin. an easy way to set this is to again test the circuit at the minimum temperature and maximum v dd that the design will be expected to perform in; then, look at the output. this should be the maximum ampli- tude of the clock output. if there is clipping, or the sine wave is distorted near v dd and v ss , increasing load capacitors may cause too much current to flow through the crystal, or push the value too far from the manufac- turer?s load specification. to adjust the crystal current, add a trimmer potentiometer between the crystal inverter output pin and c2, and adjust it until the sine wave is clean. the crystal will experience the highest drive currents at the low temperature and high v dd extremes. the trimmer potentiometer should be adjusted at these limits to prevent overdriving. a series resistor, rs, of the closest standard value can now be inserted in place of the trimmer. if rs is too high, perhaps more than 20 k ? , the input will be too isolated from the output, making the clock more susceptible to noise. if you find a value this high is needed to prevent overdriving the crystal, try increasing c2 to compensate or changing the oscillator operating mode. try to get a combination where rs is around 10 k ? or less, and load capacitance is not too far from the manufacturer?s specification. 3.7 external clock input in ec mode, the osc1 pin is in a high-impedance state and can be driven by cmos drivers. the osc2 pin can be configured as either an i/o or the clock output (f osc /4) by selecting the clkoen bit (config2l<5>). with clkoen set ( figure 3-5 ), the clock output is avail- able for testing or synchronization purposes. with clkoen clear ( figure 3-6 ), the osc2 pin becomes a general purpose i/o pin. the feedback device between osc1 and osc2 is turned off to save current. figure 3-5: external clock input operation (clkoen = 1 ) figure 3-6: external clock input operation (clkoen = 0 ) 3.8 phase lock loop (pll) branch the pll module contains two separate pll submodules: pllm and pll96mhz. the pllm sub- module is configurable as a 4x, 6x or 8x pll. the osc1 f osc /2 clock from external system pic18f osc2 (f osc /4 output) osc1 i/o ra6 (general purpose i/o) i/o clock from external pic18f system
? 2012 microchip technology inc. ds30575a-page 53 pic18f97j94 family pll96mhz submodule runs at 96 mhz and requires an input clock between 4 mhz and 48 mhz (a multiple of 4 mhz). these are selected through the plldiv<3:0> bits. figure 3-7: basic oscillator block diagram oscmux divide by n frcdiv frc oscillator (frc) primary oscillator (posc) pll module (pllm, pll96mhz)
pic18f97j94 family ds30575a-page 54 ? 2012 microchip technology inc. 3.8.1 oscillator modes and usb operation because of the timing requirements imposed by usb, an internal clock of 48 mhz is required at all times while the usb module is enabled and not in a suspended operating state. a method is provided to internally generate both the usb and system clocks from a single oscillator source. pic18f97j94 family devices use the same clock structure as most other pic18 devices, but include a two-branch pll system to generate the two clock signals. the usb pll block is shown in figure 3-8 . in this sys- tem, the input from the primary oscillator is divided down by a pll prescaler to generate a 4 mhz output. this is used to drive an on-chip 96 mhz pll frequency multiplier to drive the two clock branches. one branch uses a fixed, divide-by-2 frequency divider to generate the 48 mhz usb clock. the other branch uses a fixed, divide-by-1.5 frequency divider and configurable pll prescaler/divider to generate a range of system clock frequencies. the cpdivx bits select the system clock speed; available clock options are listed in tab l e 3 - 3 . the usb pll prescaler does not automatically sense the incoming oscillator frequency. the user must manu- ally configure the pll divider to generate the required 4 mhz output, using the plldiv<3:0> configuration bits. this limits the choices for primary oscillator frequency to a total of 8 possibilities, shown in table 3-4 . figure 3-8: 96 mhz pll block 96 mhz pll pll prescaler plldiv<3:0> input from posc input from frc 12 8 6 5 4 3 2 1 0111 0110 0101 0100 0011 0010 0001 0000 2 1.5 48 mhz clock for usb module postsclaer 64 63 ... 17.50 17.00 ... 1.25 127 126 ... 65 64 ... 1 clock output for display interface (dispclk) 2 0 g1clksel graphics clock option 2 postsclaer cpdiv<1:0> 8 4 2 1 11 10 01 00 pll output for system clock 4 mhz or 8 mhz 96 mhz branch 96 mhz pll usb clock graphics clock system clock 4 mhz branch 48 mhz branch fosc<2:0>
? 2012 microchip technology inc. ds30575a-page 55 pic18f97j94 family table 3-3: system clock options during usb operation table 3-4: valid primary oscillator configurations for usb operations 3.8.2 considerations for using the pll block all pll blocks use the lock bit (osccon2<5>) as a read-only status bit to indicate the lock status of the pll. it is automatically set after the typical time delay for the pll to achieve lock, designated as t lock . it is cleared at a por and on clock switches when the pll is selected as a clock source. it remains clear when any clock source not using the pll is selected. if the pll does not stabilize properly during start-up, the lock bit may not reflect the actual status of the pll lock, nor does it detect when the pll loses lock during normal operation. refer to the ?electrical char- acteristics? section in the specific device data sheet for further information on the pll lock interval. using any pll block with the frc oscillator provides a stable system clock for microcontroller operations. usb operation is only possible with frc oscillators that are implemented with 1/4% frequency accuracy. serial communications using usart are only possible when frc oscillators are implemented with 2% fre- quency accuracy. the pic18f97j94 family is able to meet the required oscillator accuracy for both usb and usart providing stable communication by use of its active clock tuning feature. refer to section 3.13.3 ?active clock tuning (act) module? for more information. if an application is being migrated between pic18f platforms with different pll blocks, the differences in pll and clock options may require the reconfiguration of peripherals that use the system clock. this is partic- ularly true with serial communication peripherals, such as the usarts. 3.9 secondary oscillator (sosc) in most pic18f devices, the low-power secondary oscillator (sosc) is implemented to run with a 32.768 khz crystal. the oscillator is located on the sosco and sosci device pins, and serves as a sec- ondary crystal clock source for low-power operation. it is used to drive timer1, real-time clock and calendar (rtcc) and other modules requiring a clock signal while in low-power operation. 3.9.1 enabling the secondary oscillator the operation of the sosc is selected by the foscx configuration bits or by selection of the noscx bits (osccon<2:0>). the sosc can also be enabled by setting the soscen bit in timer1, timer3 or timer5. the sosc has a long start-up time; therefore, to avoid delays for peripheral start-up, the sosc can be manually started using one of the soscen bits. mcu clock division (cpdiv<1:0>) system clock frequency (instruction rate in mips) none ( 00 )64mhz (16) ? 2 ( 01 )32mhz (8) ? 4 ( 10 )4mhz (4) ? 8 ( 11 )2mhz (1) ( 1 ) note 1: these options are not compatible with usb operation. they may be used when- ever the pll branch is selected and the usb module is disabled. input oscillator frequency clock mode pll division (plldiv<2:0>) 48 mhz ecpll ? 12 ( 111 ) 32 mhz ecpll ?? 8 ( 110 ) 24 mhz hspll, ecpll ? 6 ( 101 ) 20 mhz hspll, ecpll ? 5 ( 100 ) 16 mhz hspll, ecpll ? 4 ( 011 ) 12 mhz hspll, ecpll ? 3 ( 010 ) 8 mhz ecpll, mspll, frcpll ( 1 ) ? 2 ( 001 ) 4 mhz ecpll, mspll, frcpll ( 1 ) ? 1 ( 000 ) note 1: frcpll with 0.25% accuracy can be used for usb operation. note: because of usb clocking accuracy requirements (0.25%), not all pic18f devices support the use of the frcpll system clock configuration for usb oper- ation. refer to the specific device data sheet for details on the frc oscillator module.
pic18f97j94 family ds30575a-page 56 ? 2012 microchip technology inc. 3.9.2 secondary oscillator operation 3.9.2.1 continuous operation the sosc is always running when any of the soscen bits are set. leaving the oscillator running at all times allows a fast switch to the 32 khz system clock for lower power operation. returning to the faster main oscillator still requires an oscillator start-up time if it is a crystal-type source. this start-up time can be avoided on pll clock sources by setting the pllen bit (osccon4<5>) in advance of switching the clock source. in addition, the oscillator will need to remain running at all times for real-time clock (rtc) application using timer1 or the rtcc module. refer to section 14. ?timers? and section 29. ?real-time clock and calendar (rtcc)? in the ?pic18f family reference manual? for further details. 3.9.2.2 intermittent operation when all soscen bits are cleared, the oscillator will only operate when it is selected as the current device clock source (cosc<2:0> = 100 ). it will be disabled automatically if it is the current device clock source and the device enters sleep mode. 3.9.3 operating modes 3.9.3.1 digital mode the sosco pin can also be configured to operate as a digital clock input. the sosco pin is configured as a digital input by setting soscsel (config2l<3>) = 10 . when running in this mode, the sosco/sclki pin will operate as a digital input to the oscillator section, while the sosci pin will function as a port pin. the crystal driving circuit is disabled. the oscillator configuration fuse bits (fosc<2:0>) and new oscillator selection bits (nosc<2:0>) have no effect. 3.10 internal fast rc oscillator (frc) the frc oscillator is a fast (8 mhz nominal), internal rc oscillator. this oscillator is intended to be a precise internal rc oscillator accurate enough to provide the clock frequency necessary to maintain baud rate toler- ance for serial data transmissions, without the use of an external crystal or ceramic resonator. the pic18f device operates from the frc oscillator whenever the coscx bits are ? 111 ?, ? 110 ?, ? 001 ? or ? 000 ?. 3.10.1 enabling the frc oscillator since it serves as the system clock during device initial- ization, the frc oscillator is always enabled at a por. after the device is configured and pwrt expires, frc remains active only if it is selected as the device clock source. 3.10.2 frc postscal er mode (frcdiv) users are not limited to the nominal 8 mhz frc output if they wish to use the fast internal oscillator as a clock source. an additional frc mode, frcdiv, implements a selectable postscaler that allows the choice of a lower clock frequency, from 7 different options, plus the direct 8 mhz output. the postscaler is configured using the ircf<2:0> bits (osccon3<2:0>). assuming a nominal 8 mhz output, available lower frequency options range from 4 mhz (divide-by-2) to 31 khz (divide-by-256). the range of frequencies allows users the ability to save power at any time in an application by simply changing the ircfx bits. the frcdiv mode is selected whenever the coscx bits are ? 111 ?. 3.10.3 frc oscillator with pll mode (frcpll) the frcpll mode is selected whenever the coscx bits are ? 001 ?. in addition, this mode only functions when the direct or divide-by-2 frc postscaler options are selected (ircf<2:0> = 000 or 001 ). when using the 4x or 8x pll option, the output of the frc postscaler may also be combined with the pll to produce a nominal system clock of 16 mhz, 32 mhz or 64 mhz. although somewhat less precise in frequency than using the primary oscillator with a crystal or reso- nator, it allows high-speed operation of the device without the use of external oscillator components. for devices with the basic 4x pll block, the output of the frc postscaler block may also be combined with the pll to produce a nominal system clock of either 16 mhz or 32 mhz. although somewhat less precise in fre- quency than using the primary oscillator with a crystal or resonator, it still allows high-speed operation of the device without the use of external oscillator components. when using the 96 mhz pll block, the output of the frc postscaler block may also be combined with the pll to produce a nominal system clock of either 4 mhz, 8 mhz, 16 mhz or 32 mhz. it also produces a 48 mhz usb clock; however, this usb clock must be generated with the frc oscillator meeting the frequency accuracy requirement of usb for proper operation. refer to the specific device data sheet for details on the frc oscillator electrical characteristics. in cases where the frequency accuracy is not met for usb operation, the frcpll mode should not be used when usb is active. note: using frc postscaler values, other than ? 000 ?or ? 001 ?, will cause the clock input to the pll to be below the operating frequency input range and may cause undesirable operation.
? 2012 microchip technology inc. ds30575a-page 57 pic18f97j94 family 3.11 internal low-power rc oscillator (lprc) the lprc oscillator is separate from the frc and oscil- lates at a nominal frequency of 31 khz. lprc is the clock source for the power-up timer (pwrt), watchdog timer (wdt) and fscm circuits. it may also be used to provide a low-frequency clock source option for the device, in those applications where power consumption is critical and timing accuracy is not required. 3.11.1 enabling the lprc oscillator since it serves the power-up timer (pwrt) clock source, the lprc oscillator is enabled at por events whenever the on-board voltage regulator is disabled. after the pwrt expires, the lprc oscillator will remain on if any one of the following is true: ? the fscm is enabled. ? the wdt is enabled. ? the lprc oscillator is selected as the system clock (cosc<2:0> = 101 ). if none of the above is true, the lprc will shut off after the pwrt expires. 3.12 fail-safe clock monitor (fscm) the fail-safe clock monitor (fscm) allows the device to continue to operate, even in the event of an oscillator failure. the fscm function is enabled by programming the fscmx (clock switch and monitor) bits in config3l<5:4>. fscm is only enabled when the fscm<1:0> bits (config3l<5:4>) = 00 . when fscm is enabled, the internal lprc oscillator will run at all times (except during sleep mode). in the event of an oscillator failure, the fscm will gener- ate a clock failure trap and will switch the system clock to the frc oscillator. the user will then have the option to either attempt to restart the oscillator or execute a controlled shutdown. fscm will monitor the system clock source regardless of it s source or oscillator mode. this includes the primary oscillator for all oscillator modes and the secondary oscillator, sosc, when configured as the system clock. the fscm module takes the following actions when switching to the frc oscillator: 1. the coscx bits are loaded with ? 000 ?. 2. the cf status bit is set to indicate the clock failure. 3.12.1 fscm delay on a por, bor or wake from sleep mode event, a nominal delay (t fscm ) may be inserted before the fscm begins to monitor the system clock source. the purpose of the fscm delay is to provide time for the oscillator and/or pll to stabilize when the pwrt is not utilized. the fscm delay will be generated after the internal system reset signal, sysrst , has been released. refer to section 28.4 ?fail-safe clock monitor? for fscm delay timing information. the t fscm interval is applied whenever the fscm is enabled and the ec, hs or sosc oscillator modes are selected as the system clock. 3.12.2 fscm and slow oscillator start-up if the chosen device oscillator has a slow start-up time coming out of por, bor or sleep mode, it is possible that the fscm delay will expire before the oscillator has started. in this case, the fscm will initiate a clock failure trap. as this happens, the coscx bits are loaded with the frc oscillator selection. this will effectively shut off the original oscillator that was trying to start. the user can detect this situation and initiate a clock switch back to the desired oscillator in the trap service routine (tsr). 3.12.3 fscm and wdt the fscm and the wdt both use the lprc oscillator as their time base. in the event of a clock failure, the wdt is unaffected and continues to run on the lprc. 3.13 clock switching operation with few limitations, applications are free to switch between any of the four clock sources (primary, sosc, frc and lprc) under software control and at any time. to limit the possible side effects that could result from this flexibility, pic18f devices have a safeguard lock built into the switch process. note: for more information about the oscilla- tor failure trap, refer to section 10.0 ?interrupts? . note: please refer to the ? electrical character- istics ? section of the specific device data sheet for t fscm specification values. note: primary oscillator mode has three different submodes (ms, hs and ec), which are determined by the poscmdx configura- tion bits. while an application can switch to and from primary oscillator mode, in soft- ware, it cannot switch between the different primary submodes without reprogramming the device.
pic18f97j94 family ds30575a-page 58 ? 2012 microchip technology inc. 3.13.1 enabling clock switching to enable clock switching, the fcksm1 configuration bit must be programmed to ? 0 ?. if the fcksm1 config- uration bit is unprogrammed (? 1 ?), the clock switching function and fail-safe clock monitor function are disabled; this is the default setting. the noscx control bits (osccon<2:0>) do not control the clock selection when clock switching is disabled. how- ever, the coscx bits (osccon<6:4>) will reflect the clock source selected by the fosc configuration bits. 3.13.2 oscillator switching sequence at a minimum, performing a clock switch requires this basic sequence: 1. if desired, read the coscx bits (osccon<6:4>) to determine the current oscillator source. 2. clear the clklock bit (osccon2<7>) to enable writes to the noscx bits (osccon<2:0>). 3. write the appropriate value to the noscx control bits (osccon<2:0>) for the new oscillator source. once the basic sequence is completed, the system clock hardware responds automatically as follows: 1. the clock switching hardware compares the cosc status bits with the new value of the nosc control bits. if they are the same, then the clock switch is a redundant operation. if they are different, then a valid clock switch has been initiated. 2. the new oscillator is turned on by the hardware if it is not currently running. if a crystal oscillator must be turned on, the hardware will wait until the ost expires. if the new source is using the pll, then the hardware waits until a pll lock is detected (lock = 1 ). 3. the hardware waits for the new clock source to stabilize and then performs the clock switch. 4. the hardware clears the oswen bit to indicate a successful clock transition has occurred. 5. the noscx bit values are transferred to the coscx status bits. 6. the old clock source is turned off at this time, with the exception of lprc (if wdt or fscm is enabled) or sosc (if it is enabled by one of the timer sources). the timing of the transition between clock sources is shown in figure 3-9 . figure 3-9: clock trans ition timing diagram note 1: the processor will continue to execute code throughout the clock switching sequence. timing-sensitive code should not be executed during this time. 2: direct clock switches between any primary oscillator mode with pll and frcpll mode are not permitted. this applies to clock switches in either direc- tion. in these instances, the application must switch to frc mode as a transition clock source between the two pll modes. old clock source new clock source system clock both oscillators active new source enabled new source stable old source disabled note: the system clock can be any selected s ource (primary, secondary, frc or lprc). nosc = cosc (old oscillator enabled) nosc cosc (oscillator source in process of transition) nosc = cosc (new oscillator source enabled)
? 2012 microchip technology inc. ds30575a-page 59 pic18f97j94 family a recommended code sequence for a clock switch includes the following: 1. disable interrupts during the osccon register unlock and write sequence. 2. clear the clklock bit (osccon2<7>) to enable writes to the noscx bits (osccon<2:0>). 3. write new oscillator source to noscx control bits. 4. continue to execute code that is not clock-sensitive (optional). 5. invoke an appropriate amount of software delay (cycle counting) to allow the selected oscillator and/or pll to start and stabilize. 6. check to see if cosc contains the new oscillator values that were requested in step 3. 3.13.2.1 clock switching considerations when incorporating clock switching into an application, users should keep certain things in mind when designing their code. ? if the new clock source is a crystal oscillator, the clock switch time will be dominated by the oscillator start-up time. ? if the new clock source does not start, or is not present, the clock switching hardware will wait indefinitely for the new clock source. the user can detect this situation because the coscx bits will not change to reflect the new desired oscillator settings. ? switching to a low-frequency clock source, such as the secondary oscillator, will result in very slow device operation. 3.13.3 active clock tuning (act) module the active clock tuning (act) module continuously adjusts the 8 mhz internal oscillator, using an available external reference, to achieve 0.20% accuracy. this eliminates the need for a high-speed, high-accuracy external crystal when the system has an available lower speed, lower power, high-accuracy clock source available. systems implementing a real-time clock calendar (rtcc) or a full-speed usb application can take full advantage of the act module. 3.13.3.1 active clock tuning operation the act module defaults to the disabled state after any reset. when the act module is disabled, the user can write to the tun<6:0> bits in the osctune register to manually adjust the 8 mhz internal oscillator. the module is enabled by setting the acten bit of the actcon register. when enabled, the act module takes control of the osctune register. the act module uses the selected act reference clock to tune the 8 mhz internal oscillator to an accuracy of 8 mhz 0.2%. the tuning automatically adjusts the osctune register every reference clock cycle. 3.13.3.2 active clock tuning source selection the act reference clock is selected with the actsrc bit of the actcon register. the reference clock sources are provided by the: ? usb module in full-speed operation (act_clk) ? secondary clock at 32.768 khz (sosc_clk) 3.13.3.3 act lock status the actlock bit will be set to ? 1 ?, when the 8 mhz internal oscillator is successfully tuned. the bit will be cleared by the following conditions: ? out of lock condition ? device reset ? module is disabled 3.13.3.4 act out-of-range status if the act module requires an osctune value outside the range to achieve 0.20% accuracy, then the act out-of-range (actors) status bit will be set to ? 1 ?. an out-of-range status can occur: ? when the 8 mhz internal oscillator is tuned to its lowest frequency and the next act_clk event requests a lower frequency. ? when the 8 mhz internal oscillator is tuned to its highest frequency and the next act_clk event requests a higher frequency. when the act out-of-range event occurs, the 8 mhz internal oscillator will continue to use the last written osctune value. when the osctune value moves back within the tunable range and actlock is established, the actors bit is cleared to ? 0 ?. note: the application should not attempt to switch to a clock with a frequency lower than 100 khz when the fscm is enabled. clock switching in these instances may generate a false oscillator fail trap and result in a switch to the internal fast rc oscillator.
pic18f97j94 family ds30575a-page 60 ? 2012 microchip technology inc. figure 3-10: active clock tuning block diagram note 1: when the act module is enabled, the osctune register is only updated by the module. writes to the osctune register by the user are inhibited, but reading the register is permitted. 2: after disabling the act module, the user should wait three instructions before writ- ing to the osctune register. actsrc fsusb_clk sosc_clk acten active clock tuning module act_clk enable acten write osctune acten actud 8 mhz internal osc 1 0 osctune<6:0> 7 7 act data sfr data
? 2012 microchip technology inc. ds30575a-page 61 pic18f97j94 family register 3-10: actcon: active clock tuning ( act) control register note 1: the actsrc bit should only be changed when acten = 0 . r/w-0 u-0 r/w-0 r/w-0 r-0 r/w-0 r-0 r/w-0 acten ? actsidl actsrc (1) actlock actlock- pol actors actor- spol bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 acten: active clock tuning selection bit 1 = act module is enabled, updates to osctune are exclusive to the act module 0 = act module is disabled bit 6 unimplemented: reads as ? 0 ? bit 5 actsidl: active clock tuning stop in idle bit 1 = active clock tuning stops during idle mode 0 = active clock tuning continues during idle mode bit 4 actsrc: active clock tuning source selection bit 1 = the frc oscillator is tuned to approximately match the usb host clock tolerance 0 = the frc oscillator is tuned to approximately match the 32.768 khz sosc tolerance bit 3 actlock: active clock tuning lock status bit 1 = locked; internal oscillator is within 0.20% 0 = not locked; internal oscillator tuning has not stabilized within 0.20% bit 2 actlockpol: active clock tuning lock interrupt polarity bit 1 = act lock interrupt is generated when actlock is ? 0 ? 0 = act lock interrupt is generated when actlock is ? 1 ? bit 1 actors: active clock tuning out-of-range status bit 1 = out-of-range; oscillator frequency is outside of the osctune range 0 = in-range; oscillator frequency is within the osctune range bit 0 actorspol: active clock tuning out of range interrupt polarity bit 1 = act out of range interrupt is generated when actors is ? 0 ? 0 = act out of range interrupt is generated when actors is ? 1 ?
pic18f97j94 family ds30575a-page 62 ? 2012 microchip technology inc. 3.13.4 abandoning a clock switch in the event the clock switch does not complete, it can be abandoned by setting the noscx bits to their previ- ous values. this abandons the clock switch process, stops and resets the ost (if applicable), and stops the pll (if applicable). a clock switch procedure can be aborted at any time. a clock switch that is already in progress can also be aborted by performing a second clock switch. 3.13.5 entering sleep mode during a clock switch if the device enters sleep mode during a clock switch operation, the operation is abandoned. the processor keeps the old clock selection and the noscx bits return to their previous values (the same as cosc). the sleep instruction is then executed normally. 3.14 two-speed start-up two-speed start-up is an automatic clock switching feature that is independent of the manually controlled clock switching previously described. it helps to mini- mize the latency period, from oscillator start-up to code execution, by allowing the microcontroller to use the frc oscillator as a clock source until the primary clock source is available. this feature is controlled by the ieso configuration bit (config2l<7>) and operates independently of the state of the fscm configuration bits. two-speed start-up is particularly useful when an external oscillator is selected by the foscx configura- tion bits, and a crystal-based oscillator (either a primary or secondary oscillator) may have a longer start-up time. as an internal rc oscillator, the frc clock source is available almost immediately following a por or device wake-up. with two-speed start-up, the device starts executing code on por in its default oscillator configuration (frc). it continues to operate in this mode until the external oscillator source, specified by the foscx configuration bits, becomes stable; at which time, it automatically switches to that source. two-speed start-up is used on wake-up from the power-saving sleep mode. the device uses the frc clock source until the selected primary clock is ready. it is not used in idle mode, as the device will be clocked by the currently selected clock source until the primary clock source becomes available. 3.14.1 special considerations for using two-speed start-up while using the frc oscillator in two-speed start-up, the device still obeys the normal command sequences for entering power-saving modes, including sleep and idle instructions. in practice, this means that user code can change the nosc<2:0> bit settings or issue #sleep instructions before the ost times out. this would allow an application to briefly wake-up, perform routine ?housekeeping? tasks and return to sleep before the device starts to operate from the external oscillator. user code can also check which clock source is cur- rently providing the device clocking by checking the status of the cosc<2:0> bits against the nosc<2:0> bits. if these two sets of bits match, the clock switch has been completed successfully and the device is running from the intended clock source; the primary oscillator is providing the clock. otherwise, frc is providing the clock during wake-up from reset or sleep mode. 3.15 reference clock output module (refo1 and refo2) 3.15.1 applications the pic18f97j94 family has two reference clock output modules. each of the reference clock output modules provides the user with the ability to send out a programmed output clock onto the refo1or refo2 pins. 3.15.2 reference clock source the module provides the ability to select one of the following clock sources: ? primary crystal oscillator (posc) ? secondary crystal oscillator (sosc) ? 32.768 khz internal oscillator (intosc) ? fast internal oscillator (frc) ? raw system clock ( sys_clk ) ? peripheral clock ( p1_clk ) it includes a programmable clock divider with ratios ranging from 1:1 to 1:65534. when the clock source is a crystal or internal oscillator, the rslp bit (refoxcon<3> can be set to continue refox operation while the device is in sleep mode.
? 2012 microchip technology inc. ds30575a-page 63 pic18f97j94 family 3.15.3 clock synchronization the reference clock output is enabled only once (on = 1 ). note that the source of the clock and the divider values should be chosen prior to the bit being set to avoid glitches on the refo output. once the on bit is set, its value is synchronized to the reference clock domain to enable the output. this ensures that no glitches will be seen on the output. sim- ilarly, when the on bit is cleared, the output and the associated output enable signals will be synchronized, and disabled on the falling edge of the reference clock. note that with large divider values, this will cause the refo to be enabled for some period after on is cleared. 3.15.4 operation in sleep mode if any clock source, other than the peripheral clock, is used as a base reference (i.e., rosel<3:0> ? 0001 ), the user has the option to configure the behavior of the oscillator in sleep mode. the rslp configuration bit determines if the oscillator will continue to run in sleep. if rslp = 0 , the oscillator will be shut down in sleep (assuming no other consumers are requesting it). if rslp = 1 , the oscillator will continue to run in sleep. the reference clock output is synchronized with the sleep signal to avoid any glitches on its output. 3.15.5 module enable signal the refox module may be enabled or disabled using the refoxmd register bit (pmd3, bit 1 or 0). the module also needs to be turned on using the on bit (refo1con<7>). 3.15.5.1 registers and bits this module provides the following device registers and/or bits: ? refoxcon ? reference clock output control register ? refoxcon1 ? reference clock output control 1 register ? refoxcon2 ? reference clock output control 2 register ? refoxcon3 ? reference clock output control 3 register
pic18f97j94 family ds30575a-page 64 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 65 pic18f97j94 family 4.0 power-managed modes all pic18f97j94 family devices offer a number of built-in strategies for reducing power consumption. these strategies can be particularly useful in applica- tions, which are both power-constrained (such as battery operation), yet require periods of full-power operation for timing-sensitive routines (such as serial communications). aside from their low-power architecture, these devices include an expanded range of dedicated hardware features that allow the microcontroller to reduce power consumption to even lower levels when long-term hibernation is required, and still be able to resume operation on short notice. the device has four power-saving features: ? instruction-based power-saving modes ? hardware-based power reduction features ? microcontroller clock manipulation ? selective peripheral control combinations of these methods can be used to selec- tively tailor an application?s power consumption, while still maintaining critical or timing-sensitive application features. however, it is more convenient to discuss the strategies separately. 4.1 overview of power-saving modes in addition to full-power operation, otherwise known as run mode, pic18f97j94 family devices offer three instruction-based, power-saving modes and one hard- ware-based mode. in descending order of power consumption, they are: ?idle ? sleep (including retention sleep) ? deep sleep (with and without retention) ?v bat (with and without rtcc) by powering down all four modes, different functional areas of the microcontroller allow progressive reduc- tions of operating and idle power consumption. in addi- tion, three of the modes can be tailored for more power reduction at a trade-off of some operating features. table 4-1 lists all of the operating modes (including run mode, for comparison) in order of increasing power savings and summarizes how the microcontroller exits the different modes.
pic18f97j94 family ds30575a-page 66 ? 2012 microchip technology inc. table 4-1: summary of operating modes fo r pic18f97j94 family devices with v bat power-saving features mode entry active systems exit conditions interrupts resets rtcc alarm (ds)wdt ( 3 ) v dd restore code execution resumes core peripherals data ram retention rtcc ( 1 ) dsgprx ( 2 ) all int0 only all por mclr run (default) n/a y y y y y n/a n/a n/a n/a n/a n/a n/a n/a n/a idle instruction n y y y y y y y y y y y n/a next instruction sleep modes: sleep instruction n n ( 4 ) y y y y y y y y y y n/a next instruction retention sleep instruction + r eten bit nn ( 4 ) yyyyyyyy y yn/a deep sleep modes: retention deep sleep instruction + dsen bit + reten bit n n y y y n y n y y y y n/a next instruction deep sleep instruction + dsen bit n n n y y n y n y y y y n/a reset vector v bat : with rtcc hardware n n n y y n n n n n n n y reset vector w/o rtcc hardware + by disabling the rtcc pmd bit nn nnynnnnn n n y note 1: if rtcc is otherwise enabled in firmware. 2: data retention in the dsgpr0, dsgpr1, dsgpr2 and dsgpr3 registers. 3: deep sleep wdt in deep sleep modes; wdt in all other modes. 4: some select peripherals may continue to operate in this mo de, using either the lprc or an external clock source.
? 2012 microchip technology inc. ds30575a-page 67 pic18f97j94 family 4.2 instruction-based power-saving modes pic18f97j94 family devices have 3 instruction-based power-saving modes; two of these have additional features that allow for additional tailoring of power consumption. all three m odes are entered through the execution of the sleep instruction. in descending order of power consumption, they are: ? idle mode: the cpu is disabled, but the system clock source continues to operate. peripherals continue to operate, but can optionally be disabled. ? sleep modes: the cpu, system clock source and any peripherals that operate on the system clock source are disabled. ? deep sleep modes: the cpu system clock source, and all the peripherals except rtcc and dswdt are disabled. this is the lowest power mode for the device. the power to ram and flash is also disabled. deep sleep modes represent the lowest power modes available without removing power from the application. idle and sleep modes are entered directly with the sleep statement. having idlen (osccon<7>) set prior to the sleep statement will put the device into idle mode. for deep sleep mode, it is necessary to set the dsen bit (dsconh<7>). to prevent inadvertent entry into deep sleep mode, and possible loss of data, the dsen bit must be written to twice. the write need not be consecutive instructions; however, it is a better practice to write both, one after the other. it is also recommended to clear the dscon1 register before setting the dsen bit ( example 4-1 ). example 4-1: sleep assembly syntax the instruction-based power-saving modes are exited as a result of several different hardware triggers. when the device exits one of these three operating modes, it is said to ?wake-up?. the characteristics of the power-saving modes are described in the subsequent sections. 4.2.1 interrupts coincident with power save instructions any interrupt that coincides with the execution of a sleep instruction will be held off until entry into sleep, idle or deep sleep mode is completed. the device will then wake-up from the power-managed mode. interrupts that occur during the deep sleep unlock sequence will interrupt the mandatory unlock sequence and cause a failure to enter deep sleep. for this reason, it is recommended to disable all interrupts during the deep sleep unlock sequence. 4.2.2 retention regulator a second on-chip voltage regulator is used for power management in sleep and deep sleep modes. this regulator, also known as the retention regulator, sup- plies core logic and other circuits with power at a lower v core level, about 1.2v nominal. running these circuits at a lower voltage allows for an additional incremental power saving over the normal minimum v core level. in retention sleep modes, using the regulator main- tains the entire data ram and its contents, instead of just a few protected registers. this allows the device to exit a power-saving mode and resume code execution as its previous state. the retention regulator is controlled by the configuration bit, reten (config7l<0>), and the sreten bit (rcon4<4>). the reten bit makes the retention regulator available for software control. by default (reten = 1 ), the regulator is disabled and the sreten bit has no effect. programming reten (= 0 ) allows the sreten bit to control the regulator?s operation, leaving its use in power-saving modes at the user?s discretion. setting the sreten bit prior to executing the sleep instruction puts the device into retention sleep mode. if the dsen bit was also unlocked and set prior to the instruction, the device will enter retention deep sleep mode. the retention regulator is not available outside of sleep, deep sleep or v bat modes. enabling it while the device is operating in run or idle modes does not allow the device to operate at a lower level of v core . note: sleep_mode and idle_mode are con- stants defined in the assembler include file for the selected device. clrf dscon1 clrf dscon1 bsf dscon1,7 bsf dscon1,7 sleep or movlw 0x80 movwf dscon1 movwf dscon1 sleep
pic18f97j94 family ds30575a-page 68 ? 2012 microchip technology inc. 4.2.3 idle mode when the device enters idle mode, the following events occur: ? the cpu will stop executing instructions. ? the wdt is automatically cleared. ? the system clock source will remain active and the peripheral modules, by default, will continue to operate normally from the system clock source. peripherals can optionally be shut down in idle mode using their ?stop in idle? control bit. (see peripheral descriptions for further details.) ? if the wdt or fscm is enabled, the lprc will also remain active. the processor will wake-up from idle mode on the following events: ? on any interrupt that is individually enabled. ? on any source of device reset. ? on a wdt time-out. upon wake-up from idle mode, the clock is reapplied to the cpu and instruction execution begins immediately, starting with the instruction following the sleep instruc- tion, or the first instruction in the interrupt service routine (isr). 4.2.3.1 time delays on wake-up from idle mode unlike a wake-up from sleep mode, there are no addi- tional time delays associated with wake-up from idle mode. the system clock is running during idle mode, therefore, no start-up times are required at wake-up. 4.2.3.2 wake-up from idle on interrupt any source of interrupt that is individually enabled using the corresponding control bit in the piex register, will be able to wake-up the processor from idle mode. when the device wakes from idle mode, one of two options may occur: ? if the gie bit is set, the processor will wake and the program counter will begin execution at the interrupt vector. ? if the gie bit is not set, the processor will wake and the program counter will continue execution following the sleep instruction. the pd status bit (rcon<2>) is set upon wake-up. 4.2.3.3 wake-up from idle on reset any reset, other than a power-on reset (por), will wake-up the cpu from idle mode on any device reset, except a por. 4.2.3.4 wake-up from idle on wdt time-out if the wdt is enabled, then the processor will wake-up from idle mode on a wdt time-out and continue code execution with the instruction following the sleep instruction that initiated idle mode. note that the wdt time-out does not reset the device in this case. the to bit (rcon<3>) will be set. 4.2.4 sleep modes most pic18f97j94 family devices that incorporate power-saving features and v bat , offer two distinct sleep modes: sleep mode and retention sleep mode. the characteristics of both sleep modes are: ? the system clock source is shut down. if an on-chip oscillator is used, it is turned off. ? the device current consumption will be optimum, provided no i/o pin is sourcing the current. ? the fail-safe clock monitor (fscm) does not operate during sleep mode since the system clock source is disabled. ? the lprc clock will continue to run in sleep mode if the wdt is enabled. ? if brown-out reset (bor) is enabled, the brown-out reset (bor) circuit remains operational during sleep mode. ? the wdt, if enabled, is automatically cleared prior to entering sleep mode. ? some peripherals may continue to operate in sleep mode. these peripherals include i/o pins that detect a change in the input signal or peripherals that use an external clock input. any peripheral that operates from the system clock source will be disabled in sleep mode. the processor will exit, or ?wake-up? from sleep on one of the following events: ? on any interrupt source that is individually enabled ? on any form of device reset ? on a wdt time-out
? 2012 microchip technology inc. ds30575a-page 69 pic18f97j94 family 4.2.4.1 retention sleep mode retention sleep mode allows for additional power sav- ings over sleep mode by maintaining key systems from the lower power retention regulator. when the retention regulator is used, the normal on-chip voltage regulator (operating at 1.8v nominal) is turned off and will enable a low-power (1.2v typical) regulator. by using a lower voltage, a lower total power consumption is achieved. retention sleep also offers the advantage of maintain- ing the contents of the data ram. as a trade-off, the wake-up time is longer than that for sleep mode. retention sleep mode is controlled by the sreten bit (rcon4<4>) and the reten configuration bit, as described in section 4.2.2, retention regulator . 4.3 clock source considerations when the device wakes up from either of the sleep modes, it will restart the same clock source that was active when sleep mode was entered. wake-up delays for the different oscillator modes are shown in table 4-3 and ta b l e 4 - 4 , respectively. if the system clock source is derived from a crystal oscil- lator and/or the pll, the oscillator start-up timer (ost) and/or pll lock times must be applied before the system clock source is made available to the device. as an exception to this rule, no oscillator delays are necessary if the system clock source is the secondary oscillator and it was running while in sleep mode. 4.3.1 slow oscillator start-up the ost and pll lock times may not have expired when the power-up delays have expired. to avoid this condition, one can enable two-speed start-up by the device that will run on frc until the clock source is stable. once the clock source is stable, the device will switch to the selected clock source. 4.3.2 wake-up from sleep on interrupt any source of interrupt that is individually enabled, using its corresponding control bit in the piex registers, can wake-up the processor from sleep mode. when the device wakes from sleep mode, one of two following actions may occur: ? if the gie bit is set, the processor will wake and the program counter will begin execution at the interrupt vector. ? if the gie bit is not set, the processor will wake and the program counter will continue execution following the sleep instruction that initiated sleep mode. 4.3.3 wake-up from sleep on reset all sources of device reset will wake-up the processor from sleep mode. 4.3.4 wake-up from sleep on watchdog time-out if the watchdog timer (wdt) is enabled and expires while the device is in sleep mode, the processor will wake-up. the swdten status bit (rcon2<5>) is set to indicate that the device resumed operation due to the wdt expiration. note that this event does not reset the device. operation continues from the instruction fol- lowing the sleep instruction that initiated sleep mode. 4.3.5 control bit summary for sleep modes table 4-2 shows the settings for the bits relevant to sleep modes. table 4-2: bit settings for all sleep modes 4.3.6 wake-up delays the restart delay, associated with waking up from sleep and retention sleep modes, parallel each other in terms of clock start-up times. they differ in the time it takes to switch over from their respective regulators. the delays for the different oscillator modes are shown in table 4-3 and ta b l e 4 - 4 , respectively. mode dsen dsconh<7> retention regulator reten config7l<0> sreten rcon4<4> state sleep x1x disabled x00 disabled retention sleep x01 enabled
pic18f97j94 family ds30575a-page 70 ? 2012 microchip technology inc. table 4-3: delay times for exiting from sleep mode table 4-4: delay times for exiti ng from retention sleep mode clock source exit delay oscillator delay notes ec t pm ? 1 ecpll t pm t lock 1 , 3 ms, hs t pm t ost 1 , 2 mspll, hspll t pm t ost + t lock 1 , 2 , 3 sosc (off during sleep) t pm t ost 1 , 2 (on during sleep) t pm ? 1 frc, frcdiv t pm t frc 1 , 4 lprc (off during sleep) t pm t lprc 1 , 4 (on during sleep) t pm ? 1 frcpll t pm t lock 1 , 3 note 1: t pm = start-up delay for program memory stabilization. 2: t ost = oscillator start-up timer (ost); a delay of 1024 oscillator periods before the oscillator clock is released to the system. 3: t lock = pll lock time. 4: t frc and t lprc are rc oscillator start-up times. clock source exit delay oscillator delay notes ec t retr + t pm ? 1 , 2 ecpll t retr + t pm t lock 1 , 2 , 4 ms, hs t retr + t pm t ost 1 , 2 , 3 mspll, hspll t retr + t pm t ost + t lock 1 , 2 , 3 , 4 sosc (off during sleep) t retr + t pm t ost 1 , 2 , 3 (on during sleep) t retr + t pm ? 1 , 2 frc, frcdiv t retr + t pm t frc 1 , 2 , 5 lprc (off during sleep) t retr + t pm t lprc 1 , 2 , 5 (on during sleep) t retr + t pm ? 1 , 2 frcpll t retr + t pm t lock 1 , 2 , 4 note 1: t retr = retention regulator start-up delay. 2: t pm = start-up delay for program memory stabilization; applicable only when ipen (rcon<7>) = 0 . 3: t ost = oscillator start-up timer; a delay of 1024 oscillator periods before the oscillator clock is released to the system. 4: t lock = pll lock time. 5: t frc and t lprc are rc oscillator start-up times.
? 2012 microchip technology inc. ds30575a-page 71 pic18f97j94 family 4.4 deep sleep modes the deep sleep modes puts the device into its lowest power consumption states without requiring the use of external switches to remove power from the device. there are two modes available: deep sleep mode and retention deep sleep mode. during both deep sleep modes, the power to the microcontroller core is removed to reduce leakage current. therefore, most peripherals and functions of the microcontroller become unavailable during deep sleep. however, a few specific peripherals and func- tions are powered directly from the v dd supply rail of the microcontroller, and therefore, can continue to function in deep sleep. in addition, four data memory locations, dsgpr0, dsgpr1, dsgpr2 and dsgpr3, are preserved for context information after an exit from deep sleep. deep sleep has a dedicated deep sleep brown-out reset (dsbor) and a deep sleep watchdog timer reset (dswdt) for monitoring voltage and time-out events in deep sleep mode. the dsbor and dswdt are independent of the standard bor and wdt used with other power-managed modes (run, idle and sleep). entering deep sleep mode clears the deep sleep wake-up source registers (dswakel and dswakeh). if enabled, the real-time clock and calendar (rtcc) continues to operate uninterrupted. when a wake-up event occurs in deep sleep mode (by reset, rtcc alarm, external interrupt (int0) or dswdt), the device will exit deep sleep mode and re-arm a power-on reset (por). when the device is released from reset, code execution will resume at the reset vector. 4.4.1 retention deep sleep mode in retention deep sleep, the retention regulator is enabled, which allows the data ram to retain data while all other systems are powered down. this also allows the device to return to code execution where it left off, instead of going through a por-like reset. as a trade-off, retention deep sleep mode has greater power consumption than deep sleep. however, it offers the lowest level of power consumption of the power-saving modes that still allows a direct return to code execution. retention deep sleep is controlled by the sreten bit (rcon4<4>) and the reten configuration bit, as described in section 4.2.2 ?retention regulator? . 4.4.2 entering deep sleep modes deep sleep modes are entered by: ? setting the dsen bit (dsconh<7>) ? executing the sleep instruction to enter retention deep sleep, the sreten bit must also be set prior to setting the dsen bit ( example 4-1 ). in order to minimize the possibility of inadvertently entering deep sleep, the dsen bit must be set by two separate write operations. to enter deep sleep, the sleep instruction must be executed after setting the dsen bit (i.e., the next instruction). if dsen is not set when sleep is executed, the device will enter a sleep mode instead. 4.4.3 deep sleep wake-up sources the device can be awakened from deep sleep modes by any of the following: ? mclr ?por ?rtcc alarm ? int0 interrupt ? dswdt event after waking from deep sleep mode, the device per- forms a por. when the device is released from reset, code execution will begin at the device?s reset vector. the software can determine if the wake-up was caused from an exit from deep sleep mode by reading the dpslp bit (rcon4<2>). if this bit is set, the por was caused by a deep sleep exit. the dpslp bit must be manually cleared by the software. the software can determine the wake-up event source by reading the dswake registers. these registers are cleared automatically when entering deep sleep mode, so software should read these registers after exiting deep sleep mode or before re-enabling this mode. 4.4.4 clock selection on wake-up from deep sleep mode for deep sleep mode, the processor will restart with the default oscillator source, selected with the foscx configuration bits. on wake-up from deep sleep, a por is generated internally, hence, the system resets to its por state with the exception of the rconx, dsconh/l and dsgprx registers. for retention deep sleep, the processor restarts with the same clock source that was selected before enter- ing retention deep sleep mode. wake-up is similar to that of sleep and retention sleep modes.
pic18f97j94 family ds30575a-page 72 ? 2012 microchip technology inc. 4.4.5 saving context data with the dsgprx registers as exiting deep sleep mode causes a por, most special function registers (sfrs) reset to their default por values. in addition, because the core power is not supplied in deep sleep mode, information in data ram may be lost when exiting this mode. applications which require critical data to be saved prior to deep sleep may use the deep sleep general purpose registers, dsgpr0, dsgpr1, dsgpr2 and dsgpr3. unlike other sfrs, the contents of these registers are pre- served while the device is in deep sleep mode. after exiting deep sleep, software can restore the data by reading the registers and clearing the release bit (dsconl<0>). any data stored in the dsgprx registers must be writ- ten twice. like other deep sleep control features, the write operations do not need to be sequential. however, back-to-back writes are a recommended programming practice. since the contents of data ram are maintained in retention deep sleep, the use of the dsgprx registers to store critical data is not necessary in this mode. 4.4.6 i/o pins during deep sleep during deep sleep, general purpose i/o pins retain their previous states. pins that are configured as inputs (tris bit is set), prior to entry into deep sleep, remain high-impedance during deep sleep. pins that are configured as outputs (tris bit is clear), prior to entry into deep sleep, will remain as output pins during deep sleep. while in this mode, they will drive the output level determined by their corresponding lat bit at the time of entry into deep sleep. once the device wakes back up, all i/o pins will continue to maintain their previous states, even after the device has finished the por sequence and is executing applica- tion code again. pins configured as inputs during deep sleep will remain high-impedance and pins configured as outputs will continue to drive their previous value. after waking up, the tris and lat registers will be reset. if firmware modifies the tris and lat values for the i/o pins, they will not immediately go to the newly configured states. once the firmware clears the release bit (dsconl<0>), the i/o pins are ?released?. this causes the i/o pins to take the states configured by their respective tris and lat bit values. if the deep sleep bor (dsbor) is enabled, and a dsbor event occurs during deep sleep (or v dd is hard-cycled to v ss ), the i/o pins will be immediately released, similar to clearing the release bit. all previous state information will be lost, including the general purpose dsgpr0, dsgpr1, dsgpr2 and dsgpr3 contents. dsgprx register contents will be maintained if the v bat pin is powered. if a mclr reset event occurs during deep sleep, the i/o pins will also be released automatically, but in this case, the dsgpr0, dsgpr1, dsgpr2 and dsgpr3 contents will remain valid. in case of mclr reset and all other deep sleep wake-up cases, application firmware needs to clear the release bit (dsconl<0>) in order to reconfigure the i/o pins. 4.4.7 deep sleep watchdog timer (dswdt) deep sleep has its dedicated wdt (dswdt). it is enabled through the dswdten configuration bit. the dswdt is equipped with a postscaler for time-outs of 2.1 ms to 25.7 days, configurable through the configura- tion bits, dswdtps<4:0>. entering deep sleep mode automatically clears the dswdt. the dswdt also has a configurable reference clock source for selecting the lprc or sosc. the reference clock source is configured through the dswdtosc configuration bit. under certain circumstances, it is possible for the dswdt clock source to be off when entering deep sleep mode. in this case, the clock source is turned on automatically (if dswdt is enabled), without the need for software inter- vention. however, this can cause a delay in the start of the dswdt counters. in order to avoid this delay, when using sosc as a clock source, the application can activate sosc prior to entering deep sleep mode. 4.4.8 deep sleep low-power brown-out reset devices with a deep sleep power-saving mode also have a dedicated bor for deep sleep modes (dsbor). it has a trip point range of 1.7v-2.3v nominal and is enabled through the dsboren (config7l<3>) configuration bit. when the device enters a deep sleep mode and receives a dsbor event, the device will not wake-up and will remain in the deep sleep mode. when a valid wake-up event occurs and causes the device to exit deep sleep mode, software can determine if a dsbor event occurred during deep sleep mode by reading the bor (dswakel<6>) status bit. 4.4.9 rtcc and deep sleep the rtcc can operate uninterrupted during deep sleep modes. it can wake-up the device from deep sleep by configuring an alarm. the rtcc clock source is configured with the rtcc clock select bits, rtcclksel<1:0>. the available reference clock sources are the lprc and sosc. if the lprc is used, the rtcc accuracy will directly depend on the lprc tolerance. if the rtcc is not required, deep sleep mode with the rtcc disabled, affords the lowest power consumption of any of the instruction-based power-saving modes.
? 2012 microchip technology inc. ds30575a-page 73 pic18f97j94 family 4.4.10 control bit summary for sleep modes table 4-5 shows the settings for the bits relevant to deep sleep modes. table 4-5: bit settings for all deep sleep modes 4.4.11 wake-up delays the reset delays associated with wake-up from deep sleep and retention deep sleep modes, in different oscillator modes, are provided in table 4-6 and table 4-7 , respectively. table 4-6: delay times for exiting from deep sleep mode instruction-based mode dsen (dsconh<7>) retention regulator dswdten (config8h<0>) reten (config7l<0>) sreten (rcon4<4>) state retention deep sleep 10 1 enabled 0 deep sleep 11 x disabled x note: the pmslp bit (rcon4<0>) allows the voltage regulator to be maintained during sleep modes. clock source exit delay oscillator delay notes ec t dswu ? ecpll t dswu t lock 1 , 3 ms, hs t dswu t ost 1 , 2 mspll, hspll t dswu t ost + t lock 1 , 2 , 3 sosc (off during sleep) t dswu t ost 1 , 2 (on during sleep) t dswu ? 1 frc, frcdiv t dswu t frc 1 , 4 lprc (off during sleep) t dswu t lprc 1 , 4 (on during sleep) t dswu ? 1 frcpll t dswu t frc + t lock 1 , 3 , 4 note 1: t dswu = deep sleep wake-up delay. 2: t ost = oscillator start-up timer; a delay of 1024 oscillator periods before the oscillator clock is released to the system. 3: t lock = pll lock time. 4: t frc and t lprc are rc oscillator start-up times.
pic18f97j94 family ds30575a-page 74 ? 2012 microchip technology inc. table 4-7: delay times for exiti ng retention deep sleep mode clock source exit delay oscillator delay notes ec t retr + t pm ? 1 , 2 , 6 ecpll t retr + t pm t lock 1 , 2 , 4 , 6 ms, hs t retr + t pm t ost 1 , 2 , 3 , 6 mspll, hspll t retr + t pm t ost + t lock 1 , 2 , 3 , 4 , 6 sosc off during sleep t retr + t pm t ost 1 , 2 , 3 , 6 on during sleep t retr + t pm ? 1 , 2 , 6 frc, frcdiv t retr + t pm t frc 1 , 2 , 5 , 6 lprc: off during sleep t retr + t pm t lprc 1 , 2 , 5 , 6 on during sleep t retr + t pm ? 1 , 2 , 6 frcpll t retr + t pm t lock 1 , 2 , 3 , 6 note 1: t pm = start-up delay for program memory stabilization; applicable only when ipen (rcon<7>) = 0 . 2: t retr = retention regulator start-up delay. 3: t ost = oscillator start-up timer (ost); a delay of 1024 oscillator periods before the oscillator clock is released to the system. 4: t lock = pll lock time. 5: t frc and t lprc = rc oscillator start-up times. 6: t flash = flash program memory ready delay. setting the pmslp bit will provide a faster wake-up.
? 2012 microchip technology inc. ds30575a-page 75 pic18f97j94 family 4.5 v bat mode v bat mode is a hardware-based power mode that maintains only the most critical operations when a power loss occurs on v dd . the mode does this by powering these systems from a back-up power source connected to the v bat pin. in this mode, the rtcc can run even when there is no power on v dd . v bat mode is entered whenever power is removed from v dd . an on-chip power switch detects the power loss from the v dd and connects the v bat pin to the retention regulator. this provides power at 1.2v to maintain the retention regulator, as well as the rtcc, with its clock source (if enabled) and the deep sleep general purpose (dsgprx) registers ( figure 4-1 ). entering v bat mode requires that a power source, dis- tinct from the main v dd power source, be available on v bat and that v dd be completely removed from the v dd pin(s). removing v dd can be either unintentional, as in a power failure, or as part of a deliberate power reduction strategy. as with deep sleep modes, the contents of the deep sleep general purpose (dsgprx) registers are main- tained by the retention regulator. since the power loss on v dd may be unforeseen, it is recommended to load any data to be saved in these registers in advance. any data stored in the dsgprx registers must be written twice. the write operations do not need to be sequential; however, back-to-back writes are a recommended programming practice. figure 4-1: v bat power topology back-up battery power switch retention regulator core peripherals dsgprx registers rtcc 1.2v v bat v dd v ss pic18f97j94 family microcontroller
pic18f97j94 family ds30575a-page 76 ? 2012 microchip technology inc. 4.5.1 wake-up from v bat modes when v dd is restored to a device in v bat mode, it auto- matically wakes. wake-up occurs with a por, after which the device starts executing code from the reset vector. all sfrs, except the deep sleep semaphores and rtcc registers are reset to their por values. if the rtcc was not configured to run during v bat mode, it will remain disabled and rtcc will not run. wake-up timing is similar to that for a normal por. wake-up from v bat mode is identified by checking the state of the vbat bit (rcon3<0>). if this bit is set when the device is awake and starting to execute the code from the reset vector, it indicates that the exit was from v bat mode. to identify future v bat wake-up events, the bit must be cleared in software. when a por event occurs with no battery connected to the v bat pin, the vbpor bit (rcon3<1>) becomes set. on the device, if there is no battery connected to the v bat pin, v bpor will indicate that the battery needs to be connected to the v bat pin. in addition, if the v bat power source falls below the level needed for deep sleep semaphore operation while in v bat mode (e.g., the battery has been drained), the vbpor bit will be set. vbpor is also set when the microcontroller is powered up the very first time, even if power is supplied to v bat . 4.6 saving context data with the dsgprx registers as exiting v bat causes a por, most special function registers reset to their default por values. in addition, because the core power is not supplied in v bat mode, information in data ram will be lost when exiting this mode. applications which require critical data to be saved, should be saved in dsgpr0, dsgpr1, dsgpr2 and dsgpr3. any data stored to the dsgprx registers must be written twice. the write operations do not need to be sequential. however, back-to-back writes are a recommended programming practice. after exiting v bat mode, software can restore the data by reading the registers. 4.6.1 i/o pins during v bat mode all i/o pins should be maintained at v ss level; no i/o pins should be given v dd (refer to ?absolute maximum ratings (?) ? in section 31.0 ?electrical characteristics? ) during v bat mode. the only exceptions are the sosci and sosco pins, which maintain their states if the secondary oscillator is being used as the rtcc clock source. it is the user?s responsibility to restore the i/o pins to their proper states, using the tris and lat bits, once v dd has been restored.
? 2012 microchip technology inc. ds30575a-page 77 pic18f97j94 family register 4-1: dsconl: deep sleep control register low register 4-2: dsconh: deep sleep control register high u-0 u-0 u-0 u-0 u-0 r-0 r/w-0, hsc r/w-0, hs ? ? ? ? ? r dsbor ( 1 ) release ( 1 ) bit 7 bit 0 legend: r = reserved bit hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown hs = hardware settable bit bit 7-3 unimplemented: read as ? 0 ? bit 2 reserved: maintained as ? 0 ? bit 1 dsbor: deep sleep bor event status bit ( 1 ) 1 = dsbor was enabled and v dd dropped below the dsbor threshold during deep sleep ( 2 ) 0 = dsbor disabled while device is in deep sleep mode bit 0 release: i/o pin state release bit ( 1 ) upon waking from deep sleep, the i/o pins maintain their previous states. clearing this bit will release the i/o pins and allow their respective tris and lat bits to control their states. note 1: this is the value when v dd is initially applied. 2: unlike all other events, a deep sleep bor event will not cause a wake-up from deep sleep; this bit is present only as a status bit. r/w-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0, hs ( 2 ) dsen ( 1 ) ? ? ? ? ? ?rtccwdis bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 dsen: deep sleep mode enable bit ( 1 ) 1 = deep sleep mode is enabled and device will enter deep sleep mode when the sleep instruction is executed 0 = deep sleep mode is not enabled bit 6-1 unimplemented: read as ? 0 ? bit 0 rtccwdis: rtcc wake-up disable bit ( 2 ) 1 = wake-up from rtcc is disabled 0 = wake-up from rtcc is enabled note 1: in order to enter deep sleep, dsen must be written to in two separate operations. the write operations do not need to be consecutive. before writing d sen, the dscon1 register should be cleared twice. 2: this is the value when v dd is initially applied.
pic18f97j94 family ds30575a-page 78 ? 2012 microchip technology inc. register 4-3: dswakel: deep sleep wake-up source register low ( 1 ) register 4-4: dswakeh: deep sleep wake-up source register high r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 dsflt bor ext dswdt dsrtc mclr icd dspor bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 dsflt: deep sleep fault detect bit 1 = a deep sleep fault was detected during deep sleep 0 = a deep sleep fault was not detected during deep sleep bit 6 bor: bor deep-sleep wake-up source enable bit 1 = dsbor event will wake device from deep sleep 0 = dsbor event will not wake device from deep sleep bit 5 ext: external interrupt wake-up source enable bit 1 = external interrupt will wake device from deep sleep 0 = external interrupt will not wake device from deep sleep bit 4 dswdt: dswdt deep-sleep wake-up source enable bit 1 = dswdt roll-over event will wake device from deep sleep 0 = dswdt roll-over event will not wake device from deep sleep bit 3 dsrtc: real-time clock and calendar alarm bit 1 = the real-time clock/calendar triggered an alarm during deep sleep 0 = the real-time clock /calendar did not trigger an alarm during deep sleep bit 2 mclr : mclr deep-sleep wake-up source enable bit 1 = the mclr reset will wake device from deep sleep 0 = the mclr reset will not wake device from deep sleep bit 1 icd: in-circuit debugger deep-sleep wake-up source enable bit 1 = in-circuit debugger will wake device from deep sleep 0 = in-circuit debugger will not wake device from deep sleep bit 0 dspor: power-on reset event bit 1 = the v dd supply por circuit was active and a por event was detected 0 = the v dd supply por circuit was not active, or was active but did not detect a por event note 1: to be set in software, all bits in dswake must be written to twice. the write operations do not need to be consecutive. u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ?int0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-1 unimplemented: read as ? 0 ? bit 0 int0: deep sleep wake-up source enable bit 1 = int0 interrupt will wake device from deep sleep 0 = int0 interrupt will not wake device from deep sleep
? 2012 microchip technology inc. ds30575a-page 79 pic18f97j94 family 4.7 selective peripheral power control sleep and idle modes allow users to substantially reduce power consumption by slowing or stopping the cpu clock. even so, peripheral modules still remain clocked, and thus, consume some amount of power. there may be cases where the application needs what these modes do not provide: the ability to allocate limited power resources to the cpu while eliminating power consump- tion from the peripherals. the pic18f97j94 family addresses this requirement by allowing peripheral modules to be selectively enabled or disabled, reducing or eliminating their power consumption. 4.7.1 disabling peripheral modules most of the peripheral modules in the pic18f97j94 family architecture can be selectively disabled, reduc- ing, or essentially eliminating, their power consumption during all operating modes. two different options are available to users, each with a slightly different effect. 4.7.2 module enable bit (xxxen) many peripheral modules have a module enable bit, generically named, ?xxxen?, usually located in bit position 7 of their control registers (or primary control registers for more complex modules). here, ?xxx? represents the mnemonic form for the module of the module name. for example, the enable bit for an msspx module is ?sspen?, and so on. the bit is pro- vided for all serial and parallel communication modules and the real-time clock (rtc). clearing this bit disables the module?s operation; however, it continues to receive clock signals and draw a minimal amount of current. as with all earlier pic ? mcu devices, timers continue to be under selective operation and are controlled by their own ton bit, also located in position 7. the a/d con- verter also has a legacy enable bit, adon, that has the same function as the xxxen bits. i/o ports and features associated with them, such as input change notification and input capture, do not have their own module enable bits, since their operation is secondary to other modules. disabling modules not required for a particular applica- tion, in this manner, allows for the selective and dynamic adjusting power consumption, under software control, as the application is running. 4.7.3 peripheral module disable bit (xxmd) all peripheral modules (except for i/o ports) also have a second control bit that can disable their functionality. these bits, known as the peripheral module disable (pmd) bits, are generically named, ?xxmd? (using ?xx? as the mnemonic version of the module?s name), as shown in section 4.7.2 ?module enable bit (xxxen)? ). these bits are located in the pmdx sfrs. in contrast to the module enable bits, the xxmd bit must be set (= 1 ) to disable the module. while the pmd and module enable bits both disable a peripheral?s functionality, the pmd bit completely shuts down the peripheral, effectively powering down all circuits and removing all clock sources. this has the additional effect of making any of the module?s control and buffer registers, mapped in the sfr space, unavailable for operations. in other words, when the pmd bit is used to disable a module, the peripheral ceases to exist until the pmd bit is cleared. this differs from using the module enable bit, which allows the peripheral to be reconfigured and buffer registers preloaded, even when the peripheral?s operations are disabled. the pmd bit is most useful in highly power-sensitive applications, where even tiny savings in power consumption can determine the ability of an application to function. in these cases, the bits can be set before the main body of the application to remove those peripherals that will not be needed at all.
pic18f97j94 family ds30575a-page 80 ? 2012 microchip technology inc. register 4-5: pmd0: peripheral module disable register 0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ccp10md ccp9md ccp8md ccp7md ccp6md ccp5md ccp4md eccp3md bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ccp10md: ccp10 module disable bit 1 = the ccp10 module is disabled. all ccp10 registers are held in reset and are not writable. 0 = the ccp10 module is enable bit 6 ccp9md: ccp9 module disable bit 1 = the ccp9 module is disabled. all ccp9 registers are held in reset and are not writable. 0 = the ccp9 module is enabled bit 5 ccp8md: ccp8 module disable bit 1 = the ccp8 module is disabled. all ccp8 registers are held in reset and are not writable. 0 = the ccp8 module is enabled bit 4 ccp7md: ccp7 module disable bit 1 = the ccp7 module is disabled. all ccp7 registers are held in reset and are not writable. 0 = the ccp7 module is enabled bit 3 ccp6md: ccp6 module disable bit 1 = the ccp6 module is disabled. all ccp6 registers are held in reset and are not writable. 0 = the ccp6 module is enabled bit 2 ccp5md: ccp5 module disable bit 1 = the ccp5 module is disabled. all ccp5 registers are held in reset and are not writable. 0 = the ccp5 module is enabled bit 1 ccp4md: ccp4 module disable bit 1 = the ccp4 module is disabled. all ccp4 registers are held in reset and are not writable. 0 = the ccp4 module is enabled bit 0 eccp3md: eccp3 module disable bit 1 = the eccp3 module is disabled. all eccp3 registers are held in reset and are not writable. 0 = the eccp3 module is enabled
? 2012 microchip technology inc. ds30575a-page 81 pic18f97j94 family register 4-6: pmd1: peripheral module disable register 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eccp2md eccp1md uart4md uart3md uart2md uart1md ssp2md ssp1md bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 eccp2md: eccp2 module disable bit 1 = the eccp2 module is disabled. all eccp2 registers are held in reset and are not writable. 0 = the eccp2 module is enabled bit 6 eccp1md: eccp1 module disable bit 1 = the eccp1 module is disabled. all eccp1 registers are held in reset and are not writable. 0 = the eccp1 module is enabled bit 5 uart4md: usart4 module disable bit 1 = the usart4 module is disabled. all usart4 regi sters are held in reset and are not writable. 0 = the usart4 module is enabled bit 4 uart3md: usart3 module disable bit 1 = the usart3 module is disabled. all usart3 regi sters are held in reset and are not writable. 0 = the usart3 module is enabled bit 3 uart2md: usart2 module disable bit 1 = the usart2 module is disabled. all usart2 regi sters are held in reset and are not writable. 0 = the usart2 module is enabled bit 2 uart1md: usart1 module disable bit 1 = the usart1 module is disabled. all usart1 regi sters are held in reset and are not writable. 0 = the usart1 module is enabled bit 1 ssp2md: ssp2 module disable bit 1 = the ssp2 module is disabled. all ssp2 registers are held in reset and are not writable. 0 = the ssp2 module is enabled bit 0 ssp1md: ssp1 module disable bit 1 = the ssp1 module is disabled. all ssp1 registers are held in reset and are not writable. 0 = the ssp1 module is enabled
pic18f97j94 family ds30575a-page 82 ? 2012 microchip technology inc. register 4-7: pmd2: peripheral module disable register 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 tmr8md tmr6md tmr5md tmr4md tmr3md tmr2md tmr1md tmr0md bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr8md: timer8 module disable bit 1 = the timer8 module is disabled. all timer8 regi sters are held in reset and are not writable. 0 = the timer8 module is enabled bit 6 tmr6md: timer6 module disable bit 1 = the timer6 module is disabled. all timer6 registers are held in reset and are not writable. 0 = the timer6 module is enabled bit 5 tmr5md: timer5 module disable bit 1 = the timer5 module is disabled. all timer5 regi sters are held in reset and are not writable. 0 = the timer5 module is enabled bit 4 tmr4md: timer4 module disable bit 1 = the timer4 module is disabled. all timer4 regi sters are held in reset and are not writable. 0 = the timer4 module is enabled bit 3 tmr3md: timer3 module disable bit 1 = the timer3 module is disabled. all timer3 regi sters are held in reset and are not writable. 0 = the timer3 module is enabled bit 2 tmr2md: timer2 module disable bit 1 = the timer2 module is disabled. all timer2 regi sters are held in reset and are not writable. 0 = the timer2 module is enabled bit 1 tmr1md: timer1 module disable bit 1 = the timer1 module is disabled. all timer1 regi sters are held in reset and are not writable. 0 = the timer1 module is enabled bit 0 tmr0md: timer0 module disable bit 1 = the timer0 module is disabled. all timer0 regi sters are held in reset and are not writable. 0 = the timer0 module is enabled
? 2012 microchip technology inc. ds30575a-page 83 pic18f97j94 family register 4-8: pmd3: peripheral module disable register 3 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 txmmd ctmumd adcmd rtccmd lcdmd pspmd refo1md refo2md bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 txmmd: modulator output module disable bit 1 = t he modulator output module is disabled. all mo dulator output registers are held in reset and are not writable. 0 = the modulator output module is enabled bit 6 ctmumd: ctmu module disable bit 1 = the ctmu module is disabled. all ctmu regist ers are held in reset and are not writable. 0 = the ctmu module is enabled bit 5 adcmd: adc module disable bit 1 = the adc module is disabled. all adc register s are held in reset and are not writable. 0 = the adc module is enabled bit 4 rtccmd: rtcc module disable bit 1 = the rtcc module is disabled. all rtcc registers are held in reset and are not writable. 0 = the rtcc module is enabled bit 3 lcdmd: lcd module disable bit 1 = the lcd module is disabled. all lcd registers are held in reset and are not writable. 0 = the lcd module is enabled bit 2 pspmd: psp module disable bit 1 = the psp module is disabled. all psp registers are held in reset and not are writable. 0 = the psp module is enabled bit 1 refo1md: refo1 module disable bit 1 = the refo1 module is disabled. all refo1 registers are held in reset and are not writable. 0 = the refo1 module is enabled bit 0 refo2md: refo2 module disable bit 1 = the refo2 module is disabled. all refo2 registers are held in reset and are not writable. 0 = the refo2 module is enabled
pic18f97j94 family ds30575a-page 84 ? 2012 microchip technology inc. register 4-9: pmd4: peripheral module disable register 4 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 cmp1md cmp2md cmp3md usbmd iocmd lvdmd ?embmd bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 cmp1md: cmp1 module disable bit 1 = the cmp1 module is disabled; all cmp1 registers are held in reset and are not writable 0 = the cmp1 module is enabled bit 6 cmp2md: cmp2 module disable bit 1 = the cmp2 module is disabled; all cmp2 registers are held in reset and are not writable 0 = the cmp2 module is enabled bit 5 cmp3md: cmp3 module disable bit 1 = the cmp3 module is disabled; all cmp3 registers are held in reset and are not writable 0 = the cmp3 module is enabled bit 4 usbmd: usb module disable bit 1 = the usb module is disabled; all usb registers are held in reset and are not writable 0 = the usb module is enabled bit 3 iocmd: interrupt-on-change module disable bit 1 = the ioc module is disabled; all ioc regist ers are held in reset and are not writable 0 = the ioc module is enabled bit 2 lvdmd: low voltage detect module disable bit 1 = the lvd module is disabled; all lvd regist ers are held in reset and are not writable 0 = the lvd module is enabled bit 1 unimplemented: read as ? 0 ? bit 0 embmd: emb module disable bit 1 = the emb module is disabled; all emb regist ers are held in reset and are not writable 0 = the emb module is enabled
? 2012 microchip technology inc. ds30575a-page 85 pic18f97j94 family 5.0 reset the pic18f97j94 family devices differentiate between various kinds of reset: a) power-on reset (por) b) mclr reset c) watchdog timer (wdt) reset d) configuration mismatch (cm) e) brown-out reset (bor) f) reset instruction g) stack underflow/overflow reset this section discusses resets generated by mclr , por and bor, and covers the operation of the various start-up timers. for information on wdt resets, see section 28.2 ?watchdog timer (wdt)? . for stack reset events, see section 6.1.4.4 ?stack full and underflow resets? . for deep sleep mode, see section 4.4 ?deep sleep modes? . a simplified block diagram of the on-chip reset circuit is shown in figure 5-1 . 5.1 rcon registers device reset events are tracked through the rcon, rcon2, rcon3 and rcon4 registers ( register 5-1 , register 5-2 , register 5-3 and register 5-4 ). the regis- ter bits indicate that a specific reset event has occurred. depending on the definition, status bits may be set or cleared by the event, and re-initialized by the applica- tion, after the event to the opposite state. setting or clearing reset status bits does not cause a reset. the state of these flag bits, taken together, can be read to indicate the type of reset that just occurred. the rcon register also has a control bit for setting interrupt priority (ipen). interrupt priority is discussed in section 10.0 ?interrupts? . figure 5-1: simplified block diagram of on-chip reset circuit external reset mclr v dd osc1 v dd rise detect ost/pwrt intosc (1) por pulse ost 10-bit ripple counter pwrt internal reset 11-bit ripple counter enable ost (2) enable pwrt note 1: this is the intosc source from the internal oscillator bl ock and is separate from the rc oscillator of the clki pin. 2: see table 5-1 for time-out situations. brown-out reset boren reset instruction stack pointer stack full/underflow reset sleep idle 1024 cycles 1 ms 32 ? s mclre wdt time-out s r q
pic18f97j94 family ds30575a-page 86 ? 2012 microchip technology inc. register 5-1: rcon: re set control register r/w-0 u-0 r/w-1 r/w-1 r-1 r-1 r/w-0 ( 1 ) r/w-0 ipen ?cm ri to pd por bor bit 7 bit 0 legend: hc = hardware clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ipen: interrupt priority enable register bit 1 = prioritized interrupts are enabled 0 = prioritized interrupts are disabled bit 6 unimplemented : read as ? 0 ? bit 5 cm : configuration mismatch flag bit 1 = a configuration mismatch reset has not occurred 0 = a configuration mismatch reset occurred; must be set in software once the reset occurs bit 4 ri : reset instruction flag bit 1 = the reset instruction was not executed (set by firmware only) 0 = the reset instruction was executed, causing a device reset (must be set in software after a brown-out reset occurs) bit 3 to : watchdog time-out flag bit 1 = set by power-up, clrwdt instruction or sleep instruction 0 = a wdt time-out occurred bit 2 pd : power-down detection flag bit 1 = set by power-up or by the clrwdt instruction 0 = set by execution of the sleep instruction bit 1 por : power-on reset status bit ( 1 ) 1 = a power-on reset has not occurred (set by firmware only) 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = a brown-out reset has not occurred (set by firmware only) 0 = a brown-out reset occurred (must be set in software after a brown-out reset occurs) note 1: brown-out reset is said to have occurred when bor is ? 0 ? and por is ? 1 ? (assuming that por was set to ? 1 ? by software immediately after a power-on reset).
? 2012 microchip technology inc. ds30575a-page 87 pic18f97j94 family register 5-2: rcon2: rese t control register 2 r/w-0, hs u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 extr ( 1 ) ?swdten ( 2 ) ? ? ? ? ? bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 extr: external reset (mclr ) pin bit ( 1 ) 1 = a master clear (pin) reset has occurred 0 = a master clear (pin) reset has not occurred bit 6 unimplemented : read as ? 0 ? bit 5 swdten: software controlled watchdog timer enable bit ( 2 ) 1 = watchdog timer is on 0 = watchdog timer is off bit 4-0 unimplemented : read as ? 0 ? note 1: this bit is set in hardware; it can be cleared in software. 2: this bit has no effect unless the configuration bits, wdten<1:0> = 10 .
pic18f97j94 family ds30575a-page 88 ? 2012 microchip technology inc. register 5-3: rcon3: rese t control register 3 u-0 u-0 u-0 u-0 r/c-0 r/c-0 r/c-0 r/w-0 ? ? ? ? vddbor ( 1 ) vddpor ( 1 , 2 ) vbpor ( 1 , 3 ) vbat bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented : read as ? 0 ? bit 3 vddbor: v dd brown-out reset flag bit ( 1 ) 1 =a v dd brown-out reset has occurred 0 =a v dd brown-out reset has not occurred bit 2 vddpor: v dd power-on reset flag bit ( 1 , 2 ) 1 =a v dd power-up reset has occurred 0 =a v dd power-up reset has not occurred bit 1 vbpor: vbpor flag bit ( 1 , 3 ) 1 =a v bat por has occurred 0 =a v bat por has not occurred bit 0 vbat : v bat flag bit ( 1 ) 1 = a por exit has occurred while power was applied to v bat pin 0 = a por exit from v bat has not occurred note 1: this bit is set in hardware only; it can only be cleared in software. 2: indicates a v dd por. setting the por bit (rcon<0>) indicates a v core por. 3: this bit is set when the device is originally powered up, even if power is present on v bat .
? 2012 microchip technology inc. ds30575a-page 89 pic18f97j94 family register 5-4: rcon4: rese t control register 4 u-0 u-0 u-0 r/w-0 u-0 r/c-0 u-0 r/w-0 ? ? ? sreten ( 1 ) ? dpslp ( 2 ) ?pmslp bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented : read as ? 0 ? bit 4 sreten: retention regulator voltage sleep disable bit ( 1 ) 1 = if reten (config7l<0>) = 0 and the regulator is enabled, the device goes into retention mode in sleep 0 = the regulator is on when device?s sleep mode is enabled and the low-power mode is controlled by the pmslp bit bit 3 unimplemented : read as ? 0 ? bit 2 dpslp: deep sleep wake-up status bit (used in conjunction with the por and bor bits in rcon to determine the reset source) ( 2 ) 1 = the last exit from reset was caused by a normal wake-up from deep sleep 0 = the last exit from reset was not due to a wake-up from deep sleep bit 1 unimplemented : read as ? 0 ? bit 0 pmslp: program memory power during sleep bit 1 = program memory bias voltage remains powered during sleep 0 = program memory bias voltage is powered down during sleep note 1: this bit is available only when reten (config7l<0>) = 0 . 2: this bit is set in hardware only; it can only be cleared in software.
pic18f97j94 family ds30575a-page 90 ? 2012 microchip technology inc. 5.2 power-on reset (por) the pic18f97j94 family has two types of power-on resets: ?por ?v bat por por is the legacy pic18j series power-on reset which monitors core power supply. the second, v bat por, monitors voltage on the v bat pin. these por circuits use the same technique to enable and monitor their respective power source for adequate voltage levels to ensure proper chip operation. there are two threshold voltages associated with them. the first voltage is the device threshold voltage, v por . the device threshold voltage is the voltage at which the por module becomes operable. the second voltage associated with a por event is the por circuit threshold voltage. once the correct threshold voltage is detected, a power-on event occurs and the por module hibernates to minimize current consumption. a power-on event generates an internal por pulse when a v dd rise is detected. the device supply voltage characteristics must meet the specified starting voltage, v por , and rise rate requirements, sv dd , to generate the por pulse. in particular, v dd must fall below v por before a new por is initiated. for more information on the v por and v dd rise rate specifications, refer to section 31.0 ?electrical characteristics? . 5.2.1 por circuit the por circuit behaves differently than v bat por once the por state becomes active. the internal por pulse resets the por timer and places the device in the reset state. the por also selects the device clock source identified by the oscillator configuration bits. after the por pulse is generated, the por circuit inserts a small delay, t csd , to ensure that internal device bias circuits are stable. after the expiration of t csd , a delay, t pwrt , is always inserted every time the device resumes operation after any power-down. during this time, code execution is disabled. the pwrt is used to extend the duration of a power-up sequence to permit the on-chip band gap and regulator to stabilize and to load the configuration word settings. the on-chip regulator is always enabled and its stabilization time is shorter than other concur- rently running delays, and does not extend start-up time. the power-on event clears the bor and por status bits (rcon<1:0>); it does not change for any other reset event. por is not reset to ? 1 ? by any hardware event. to capture multiple events, the user manually resets the bit to ? 1 ? in software following any power-on reset. alternatively, the vddpor (rcon3<2>) bit can be used; it is set on a v dd por event. it must be cleared after any power-on reset to detect subsequent v dd por events. after t pwrt expires, an additional start-up time for the system clock (either t ost , t iobst and t rc , depending on the source) occurs while the clock source becomes stable. internal reset is then released and the device is no longer held in reset ( ta b l e 5 - 2 ). once all of the delays have expired, the system clock is released and code execution can begin. refer to section 31.0 ?electrical characteristics? for more information on the values of the delay parameters. note: when the device exits the reset condition (begins normal operation), the device operating parameters (voltage, frequency, temperature, etc.) must be within their operating ranges; otherwise, the device will not function correctly. the user must ensure that the delay between the time power is first applied, and the time, internal reset , becomes inactive, is long enough to get all operating parameters within specification.
? 2012 microchip technology inc. ds30575a-page 91 pic18f97j94 family figure 5-2: por module timing sequence for rising v dd t csd v dd v por por circuit threshold voltage sysrst t pwrt internal power-on reset pulse occurs and begins por delay time, t csd por circuit is initialized at v por time system clock is started after t pwrt delay expires system clock is released and code execution begins por pwrt note 1: timer and interval are determined by the initial start-up oscillator configuration; t osc is for external oscillator modes, t frc is for the frc oscillator or t lprc for the internal 31 khz rc oscillator. (note 1) internal reset system reset is released after clock is stable oscillator delay and code execution
pic18f97j94 family ds30575a-page 92 ? 2012 microchip technology inc. 5.2.1.1 using the por circuit to take advantage of the por circuit, tie the mclr pin directly to v dd . this will eliminate external rc compo- nents usually needed to create a por delay. a minimum rise time for v dd is required. refer to the ?electrical characteristics? section of the specific device data sheet for more information. depending on the application, a resistor may be required between the mclr pin and v dd . this resistor can be used to decouple the mclr pin from a noisy power supply rail. figure 5-3 displays a possible por circuit for a slow power supply ramp up. the external por circuit is only required if the device would exit reset before the device v dd is in the valid operating range. the diode, d, helps discharge the capacitor quickly when v dd powers down. figure 5-3: exte rnal power-on reset circuit (for slow v dd power-up) 5.2.2 v bat power-on-reset (vbpor) the device will remain in v bat mode as long as no power is present on v dd . the vbpor is active when the device is operating in v bat mode and deriving power from the v bat pin. similar to the por, the circuit monitors v bat voltage and holds the device in reset until adequate voltage is present to power up the device. after exiting the v bat por condition, the vbpor (rcon3<1>) bit is set. all other registers will be in a por state, including deep sleep semaphores. minimum v bat ramp time and rearm voltage require- ments apply. refer to parameters d003 and d004 in section 31.0 ?electrical characteristics? for details. the device does not execute code in v bat mode. also, there is no power-up timer associated with vbpor. after v dd power is restored, the device exits v bat mode and the vbat (rcon3<0>) bit is set. all other registers, except those associated with rtcc, its clock source and the deep sleep semaphores (dsgprx), will be in a por state. for more information about v bat mode, see section 4.5 ?vbat mode? . 5.3 master clear reset (mclr ) whenever the mclr pin is driven low, the device asyn- chronously asserts sysrst , provided the input pulse on mclr is longer than a certain minimum width, t mc l (see section 31.0 ?electrical characteristics? ). when the mclr pin is released, sysrst is also released. the reset vector fetch starts from the sysrst release. the processor continues to use the existing clock source that was in use before the mclr reset occurred. the extr status bit (rcon2<7>) is set to indicate the mclr reset. 5.4 watchdog timer reset (wdt) whenever a watchdog timer time-out occurs, the device asynchronously asserts sysrst . the clock source remains unchanged. note that a wdt time-out during sleep or idle mode will wake-up the processor, but not reset the processor. the to bit (rcon<3>) is cleared when a wdt time-out occurs. software must set this bit to initialize the flag. for more information, refer to section 28.2 ?watchdog timer (wdt)? . note 1: external power-on reset circuit is required only if the v dd power-up slope is too slow. the diode, d, helps discharge the capacitor quickly when v dd powers down. 2: r < 40 k ? is recommended to make sure that the voltage drop across r does not violate the device?s electric al specification. 3: r1 ? 1 k ? will limit any current flowing into mclr from external capacitor, c, in the event of mclr /v pp pin breakdown, due to electro- static discharge (esd) or electrical overstress (eos). c r1 r d v dd mclr pic18fxxjxx v dd note: the wdt described here is not the same one used in deep sleep mode. for more information on deep sleep wdt, see section 28.2 ?watchdog timer (wdt)? .
? 2012 microchip technology inc. ds30575a-page 93 pic18f97j94 family 5.5 configuration mismatch reset (cm) the configuration mismatch (cm) reset is designed to detect, and attempt to recover from, random memory corrupting events. these include electrostatic discharge (esd) events, which can cause widespread, single bit changes throughout the device and result in catastrophic failure. in pic18fxxjxx flash devices, device configuration registers (located in the configuration memory space) are continuously monitored during operation by compar- ing their values to complimentary shadow registers. if a mismatch is detected between the two sets of registers, a cm reset automatically occurs. these events are captured by the cm bit (rcon<5>) being set to ? 0 ?. this bit does not change for any other reset event. a cm reset behaves similarly to a master clear reset, reset instruction, wdt time-out reset or stack event reset. as with all hard and power reset events, the device?s configuration words are reloaded from the flash configuration words in program memory as the device restarts. 5.6 brown-out reset (bor) features the pic97j94 family has four different types of bor circuits: ? brown-out reset (bor) ?v ddcore brown-out reset (vddbor) ?v bat brown-out reset (vbatbor) ? deep sleep brown-out reset (dsbor) all four bor circuits monitor a voltage and put the device in a reset condition while the voltage is in a specified region. sfrs will reset to the bor state, including the deep sleep semaphore holding registers, dsgpr0 and dsgpr1. upon bor exit, the device remains in reset until the associated trip point voltage is exceeded. any i/o pins configured as outputs will be tri-stated. bor, vddbor and dsbor exit into run mode; vbatbor remains in v bat mode. these features differ by their power mode, monitored voltage source, trip points, control and status. refer to table 5-1 for the pic18f97j94 bor differences. table 5-1: bor feature summary ( 1 ) feature mode source trip points enable bor run, idle, sleep v ddcore 1.6v (typ) always enabled vddbor run, idle, sleep v dd v vddbor boren (config1h<0>) vbatbor v bat v bat v vbatbor vbtbor (config7l<2>) dsbor deep sleep v dd v dsbor dsboren (config7l<3>) note 1: refer to table 31-9 for details.
pic18f97j94 family ds30575a-page 94 ? 2012 microchip technology inc. 5.6.1 brown-out reset (bor) brown-out reset is the legacy pic18 ?j? feature that monitors the core voltage, v ddcore . since the regulator on the pic18f97j94 family is always enabled, this feature is always active. its trip point is non-configurable. a brown-out reset will occur as the regulator output voltage drops below, approximately 1.6v. after proper operating voltage recovers, the brown-out reset condi- tion is exited and execution begins after the power-up timer has expired. the bor (rcon<0>) bit is also cleared. this bit must be set after each brown-out and power-on reset event to detect subsequent brown-out reset events. 5.6.2 v dd bor (v ddbor ) v ddbor is enabled by setting the boren (config1h<0>) configuration bit. the low-power bor trip level is configurable to either 1.8v or 2.0v, (typ) depending on the borv (config1h<1>) config- uration bit setting. when in normal run mode, idle or normal sleep modes, the bor circuit that monitors v dd is active and will cause the device to be held in bor if v dd drops below v bor . once v dd rises back above v vddbor , the device will be held in reset until the expiration of the power-up timer, with period, t pwrt . this event is captured by the vddbor flag bit (rcon3<3>). 5.6.3 detecting v dd bor when the bor module is enabled, the vddbor (rcon3<3>) bit is set on a brown-out reset event. this makes it difficult to determine if a brown-out reset event has occurred just by reading the state of vddbor alone. a more reliable method is to simultaneously check the state of both vddpor and vddbor. this assumes that the vddpor bit is reset to ? 1 ? in software immediately after any power-on reset event. if vddbor is ? 0 ? while vddpor is ? 1 ?, it can be reliably assumed that a brown-out reset event has occurred. legacy pic18 software can use the respective por (rcon<1>) and bor (rcon<0>) bits. this technique monitors the regulator output voltage, v ddcore . to take advantage of the configuration features, it is recommended to use v ddbor instead of bor. 5.6.4 v bat brown-out reset (v batbor ) the v bat bor can be enabled/disabled using the vbtbor bit in the configuration register (config7l<2>). if the vbtbor enable bit is cleared, the v batbor is always disabled and there will be no indication of a v bat bor. if the vbtbor bit is set, the v bat por will reset the device when the battery volt- age drops below v vbatbor . after power is restored to the v bat pin, the device exits reset and returns to v bat mode. the device remains in v bat mode until power returns to the v dd pin. for more information on using the v bat feature, refer to section 4.5 ?vbat mode? . 5.6.5 deep sleep brown-out reset (dsbor) the pic18f97j94 has its dedicated bor for deep sleep mode (dsbor). it is enabled through the dsboren (config7l<3>) configuration bit. when the device enters deep sleep mode and receives a dsbor event, the device will not wake-up and will remain in deep sleep mode. when a valid wake-up event occurs and causes the device to exit deep sleep mode, software can determine if a dsbor event occurred during deep sleep mode by reading the dsbor (dsconl<1>) status bit. 5.7 reset instruction whenever the reset instruction is executed, the device asserts sysrst . this reset state does not re-initialize the clock. the clock source that is in effect prior to the reset instruction remains in effect. config- uration settings are updated and the sysrst is released at the next instruction cycle. a noise filter in the mclr reset path detects and ignores small pulses. the ri bit (rcon<4>) is cleared when a reset instruction is executed. software must set this bit to initialize the flag. 5.8 stack underflow/overflow reset a reset can be enabled on stack error conditions by setting the stvren (config1l<5>) configuration bit. see section 6.1.4.4 ?stack full and underflow resets? section for additional information. note: brown-out reset (bor) has been pro- vided to support legacy devices that can disable their internal regulator. the pic18f97j94 family?s regulator is always enabled. therefore, it?s recommended that new designs use vddbor to detect brown-out conditions.
? 2012 microchip technology inc. ds30575a-page 95 pic18f97j94 family 5.9 device reset timers pic18f97j94 family devices incorporate three sepa- rate on-chip timers that help regulate the power-on reset process. their main function is to ensure that the device clock is stable before code is executed. these timers are: ? power-up timer (pwrt) ? oscillator start-up timer (ost) ? pll lock time-out 5.9.1 power-up timer (pwrt) the power-up timer (pwrt) of the pic18f97j94 fam- ily devices is a counter which uses the intosc source as the clock input. while the pwrt is counting, the device is held in reset. the power-up time delay depends on the intosc clock and varies slightly from chip-to-chip due to temperature and process variation. see the t pwrt specification for details. the pwrt is always enabled and active after brown-out and power-on reset events. 5.9.2 oscillator start-up timer (ost) the oscillator start-up timer (ost) provides a 1024 oscillator cycle (from osc1 input) delay after the pwrt delay is over. this ensures that the crystal oscillator or resonator has started and stabilized. the ost time-out is invoked only for lp, ms, hs and hspll modes, and only on power-on reset or on exit from most power-managed modes. 5.9.3 pll lock time-out the pll is enabled by programming fosc<2:0> = 011 (config2l<2:0>. with the pll enabled, the time-out sequence, following a power-on reset, is slightly differ- ent from other oscillator modes. a separate timer is used to provide a fixed time-out that is sufficient for the pll to lock to the main oscillator frequency. this pll lock time-out (t rc ) follows the oscillator start-up time-out. 5.9.4 reset state of registers most registers are unaffected by a reset. their status is unknown on a power-on reset and unchanged by all other resets. the other registers are forced to a ?reset state? depending on the type of reset that occurred. most registers are not affected by a wdt wake-up, since this is viewed as the resumption of normal oper- ation. status bits from the rconx registers are set or cleared differently in different reset situations, as indicated in ta b l e 5 - 2 . these bits are used in software to determine the nature of the reset. table 5-2 describes the reset states for all of the special function registers. these are categorized by power-on and brown-out resets, master clear and wdt resets, and wdt wake-ups.
pic18f97j94 family ds30575a-page 96 ? 2012 microchip technology inc. table 5-2: rconx bit operation on various resets and wake-ups conditions pc dpslp extr ri t o pd idle cm bor por vddbor vddpor vbpor ( 4 , 6 ) vbat ( 4 ) dspor: ( 4 ) loss of v ddbat 000000 0 0 0 0 1 0 0 1 1 1 1 1 0 vbat: ( 4 ) loss of v dd while v bat is established 000000 1 0 0 0 1 0 0 1 1 1 1 u 1 v dd por: loss of v dd 000000 0 0 0 0 1 0 0 1 1 1 1 uu v dd bor: brown-out of v dd 000000 uu 00 1 0 0 uu 1 uuu por: loss of v ddcore 000000 0 0 0 0 1 0 0 1 1 uuu u bor brown-out of v ddcore 000000 uu 00 1 0 01 uuuuu deep sleep exit 000000 1 0 0 0 1 0 0 1 1 uuu u retention deep sleep exit 000000 1 0 0 0 1 0 0 0 0 uuu u mclr reset operational mode 000000 u 1 uu u uuuuuuuu mclr reset in idle mode 000000 u 1 u 0 ( 1 ) 0 ( 2 ) 1 ( 2 ) uuuuuuu mclr reset in sleep mode 000000 u 1 u 0 ( 1 ) 0 ( 2 ) 0 ( 2 ) uuuuuuu reset instruction reset 000000 uu 1 u u uuuuuuuu configuration mismatch reset 000000 uuuuuu 1 uu uu u u wdt reset 000000 uuu 1 u uuuuuuuu wdt reset in idle mode pc + 2 u u u 11 ( 2 ) 1 ( 2 ) uuuuuuu wdt reset in sleep mode pc + 2 u u u 1 0 ( 2 ) 0 ( 2 ) uuuuuuu interrupt in idle mode with gie = 0 pc + 2 u u u 0 ( 1 ) 1 ( 2 ) 1 ( 2 ) uuuuuuu interrupt in idle mode with gie = 1 vector u u u 0 ( 1 ) 1 ( 2 ) 1 ( 2 ) uuuuuuu interrupt in sleep mode with gie = 0 pc + 2 u u u 0 ( 1 ) 0 ( 2 ) 0 ( 2 ) uuuuuuu interrupt in sleep mode with gie = 1 vector u u u 0 ( 1 ) 0 ( 2 ) 0 ( 2 ) uuuuuuu clrwdt instruction pc + 2 u u u 0 ( 3 ) 1 uuuuuuu u idle instruction pc + 2 u u u 011 uuuuuuu sleep instruction pc + 2 u u u 000 uuuuuuu user instruction writes ? 1 ?pc + 2u 11 1 0 1 1 1 1 1 1 1 1 user instruction writes ? 0 ?pc + 2 000 0 1 0 0 0 0 0 0 0 0 note 1: the sleep instruction clears the wdto bit. 2: the clrwdt clears the wdto bit only when the wdt window feature is disabled or the wdt is in the safe window. 3: this bit is also set, flagging the loss of state re tention even though the true por condition has not occurred. 4: this bit is set in hardware only; it can only be cleared in software. 5: indicates a v dd por. setting the por bit (rcon<0>) indicates a v core por. 6: this bit is set when the device is origina lly powered up, even if power is present on v bat .
? 2012 microchip technology inc. ds30575a-page 97 pic18f97j94 family table 5-3: initialization conditions for all registers register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt tosu 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---0 uuuu ( 1 ) tosh 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ( 1 ) tosl 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ( 1 ) stkptr 64-pin 80-pin 100-pin 00-0 0000 uu-0 0000 uu-u uuuu ( 1 ) pclatu 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu pclath 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu pcl 64-pin 80-pin 100-pin 0000 0000 0000 0000 pc + 2 ( 2 ) tblptru 64-pin 80-pin 100-pin --00 0000 --00 0000 --uu uuuu tblptrh 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu tblptrl 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu tablat 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu prodh 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu prodl 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu intcon 64-pin 80-pin 100-pin 0000 000x 0000 000x uuuu uuuu ( 3 ) intcon2 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu ( 3 ) intcon3 64-pin 80-pin 100-pin 1100 0000 1100 0000 uuuu uuuu ( 3 ) indf0 64-pin 80-pin 100-pin n/a n/a n/a postinc0 64-pin 80-pin 100-pin n/a n/a n/a postdec0 64-pin 80-pin 100-pin n/a n/a n/a preinc0 64-pin 80-pin 100-pin n/a n/a n/a plusw0 64-pin 80-pin 100-pin n/a n/a n/a fsr0h 64-pin 80-pin 100-pin ---- xxxx ---- uuuu ---- uuuu fsr0l 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu wreg 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu indf1 64-pin 80-pin 100-pin n/a n/a n/a postinc1 64-pin 80-pin 100-pin n/a n/a n/a postdec1 64-pin 80-pin 100-pin n/a n/a n/a preinc1 64-pin 80-pin 100-pin n/a n/a n/a plusw1 64-pin 80-pin 100-pin n/a n/a n/a fsr1h 64-pin 80-pin 100-pin ---- xxxx ---- uuuu ---- uuuu fsr1l 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu bsr 64-pin 80-pin 100-pin ---- 0000 ---- 0000 ---- uuuu indf2 64-pin 80-pin 100-pin n/a n/a n/a legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
pic18f97j94 family ds30575a-page 98 ? 2012 microchip technology inc. postinc2 64-pin 80-pin 100-pin n/a n/a n/a postdec2 64-pin 80-pin 100-pin n/a n/a n/a preinc2 64-pin 80-pin 100-pin n/a n/a n/a plusw2 64-pin 80-pin 100-pin n/a n/a n/a fsr2h 64-pin 80-pin 100-pin ---- xxxx ---- uuuu ---- uuuu fsr2l 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu status 64-pin 80-pin 100-pin ---x xxxx ---u uuuu ---u uuuu tmr0h 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu tmr0l 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu t0con 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu reserved 64-pin 80-pin 100-pin ---- ---- ---- ---- ---- ---- osccon 64-pin 80-pin 100-pin 0qqq -qqq uuuu -uuu uuuu -uuu ipr5 64-pin 80-pin 100-pin -111 -111 -uuu -uuu -uuu -uuu iocf 64-pin 80-pin 100-pin 0000 0000 0000 0000 qqqq qqqq rcon ( 4 ) 64-pin 80-pin 100-pin 0-11 11qq 0-qq qquu u-qq qquu tmr1h 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu tmr1l 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu t1con 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu tmr2 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu pr2 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu t2con 64-pin 80-pin 100-pin -000 0000 -000 0000 -uuu uuuu ssp1buf 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu ssp1add 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ssp1stat 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ssp1con1 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ssp1con2 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu cmstat 64-pin 80-pin 100-pin ---- -xxx ---- -uuu ---- -uuu adcbuf0h 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu adcbuf0l 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu adcon1h 64-pin 80-pin 100-pin 0--- -000 u--- -uuu u--- -uuu adcon1l 64-pin 80-pin 100-pin 0000 -000 uuuu -uuu uuuu -uuu cvrconh 64-pin 80-pin 100-pin ---0 0000 ---u uuuu ---u uuuu cvrconl 64-pin 80-pin 100-pin 0000 ---0 uuuu ---u uuuu ---u table 5-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
? 2012 microchip technology inc. ds30575a-page 99 pic18f97j94 family eccp1as 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu eccp1del 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu ccpr1h 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu ccpr1l 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu ccp1con 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu pir5 64-pin 80-pin 100-pin -000 -0000 -000 -000 -uuu -uuu ( 3 ) pie5 64-pin 80-pin 100-pin -000 -000 -000 -000 -uuu -uuu ipr4 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu pir4 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ( 3 ) pie4 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu tmr3h 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu tmr3l 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu t3con 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu t3gcon 64-pin 80-pin 100-pin 0000 0x00 0000 00x0 uuuu uuuu spbrg1 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rcreg1 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu txreg1 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu txsta1 64-pin 80-pin 100-pin 0000 0010 0000 0010 uuuu uuuu rcsta1 64-pin 80-pin 100-pin 0000 000x 0000 000x uuuu uuuu t1gcon 64-pin 80-pin 100-pin 0000 0x00 0000 0x00 uuuu uuuu ipr6 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu hlvdcon 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu pspcon 64-pin 80-pin 100-pin 0000 ---- 0000 ---- uuuu ---- pir6 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ( 3 ) ipr3 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu pir3 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ( 3 ) pie3 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ipr2 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu pir2 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ( 3 ) pie2 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ipr1 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu pir1 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ( 3 ) pie1 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu table 5-3: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
pic18f97j94 family ds30575a-page 100 ? 2012 microchip technology inc. pstr1con 64-pin 80-pin 100-pin 00-0 0001 00-0 0001 uu-u uuuu osctune 64-pin 80-pin 100-pin --00 0000 --00 0000 --uu uuuu trisj 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu trish 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu trisg ( 5 ) 64-pin 80-pin 100-pin 11-1 1111 11-1 1111 uu-u uuuu trisf 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu trise 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu trisd 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu trisc 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu trisb 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu trisa 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu latj 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu lath 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu latg ( 5 ) 64-pin 80-pin 100-pin xx-x xxxx uu-u uuuu uu-u uuuu latf 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu late 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu latd 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu latc 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu latb 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu lata 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu portj 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu porth 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu portg ( 5 ) 64-pin 80-pin 100-pin xx-x x-xx xx-x x-xx uu-u u-uu portf 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu porte 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu portd 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu portc 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu portb 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu porta 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu eecon1 64-pin 80-pin 100-pin xx-0 x000 uu-0 u000 uu-u uuuu eecon2 64-pin 80-pin 100-pin ---- ---- ---- ---- ---- ---- rcon2 64-pin 80-pin 100-pin 0-0- 0--- q-u- 0--- 0-u- 1--- rcon3 64-pin 80-pin 100-pin ---0 q000 ---u 0000 ---u 0000 table 5-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
? 2012 microchip technology inc. ds30575a-page 101 pic18f97j94 family rcon4 64-pin 80-pin 100-pin 00-0 -0-0 00-u -0-u 00-u -0-u ufrml 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ufrmh 64-pin 80-pin 100-pin ---- -xxx ---- -xxx ---- -uuu uir 64-pin 80-pin 100-pin -000 0000 -000 0000 -uuu uuuu ueir 64-pin 80-pin 100-pin -000 0000 -000 0000 -uuu uuuu ustat 64-pin 80-pin 100-pin 0--0 0000 0--0 0000 u--u uuuu ucon 64-pin 80-pin 100-pin -0x0 000- -0x0 000- -uuu uuu- uaddr 64-pin 80-pin 100-pin -000 0000 -000 0000 -uuu uuuu trisvp 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu latvp 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu portvp 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu txaddrl 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu txaddrh 64-pin 80-pin 100-pin ---- 0000 ---- 0000 ---- uuuu rxaddrl 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rxaddrh 64-pin 80-pin 100-pin ---- 0000 ---- 0000 ---- uuuu dmabcl 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu dmabch 64-pin 80-pin 100-pin ---- --00 ---- --00 ---- --uu txbuf 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ssp1con3 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ssp1msk 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu baudcon1 64-pin 80-pin 100-pin 0100 0000 0100 0000 uuuu uuuu osccon2 64-pin 80-pin 100-pin 000- 000- 00q- 000- uuu- uuu- osccon3 64-pin 80-pin 100-pin ---- -001 ---- -uuu ---- -uuu osccon4 64-pin 80-pin 100-pin 000- ---- uuu- ---- uuu- ---- osccon5 64-pin 80-pin 100-pin 0-00 0000 u-uu uuuu u-uu uuuu wpub 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu pie6 64-pin 80-pin 100-pin 0000 -000 0000 -000 uuuu -uuu dmacon1 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rtccon1 64-pin 80-pin 100-pin 0-00 0000 u-uu uuuu u-uu uuuu rtccal 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu rtcvalh 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu rtcvall 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu alrmcfg 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu table 5-3: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
pic18f97j94 family ds30575a-page 102 ? 2012 microchip technology inc. alrmrpt 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu alrmvalh 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu alrmvall 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu rtccon2 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu iocp 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu iocn 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu padcfg1 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu cm1con 64-pin 80-pin 100-pin 0001 1111 0001 1111 uuuu uuuu eccp2as 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu eccp2del 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ccpr2h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccpr2l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu eccp2con 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu eccp3as 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu eccp3del 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ccpr3h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccpr3l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu eccp3con 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ccpr8h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccpr8l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccp8con 64-pin 80-pin 100-pin --00 0000 --00 0000 --uu uuuu ccpr9h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccpr9l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccp9con 64-pin 80-pin 100-pin --00 0000 --00 0000 --uu uuuu ccpr10h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccpr10l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccp10con 64-pin 80-pin 100-pin --00 0000 --00 0000 --uu uuuu tmr6 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu pr6 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu t6con 64-pin 80-pin 100-pin -000 0000 -000 0000 -uuu uuuu tmr8 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu pr8 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu t8con 64-pin 80-pin 100-pin -000 0000 -000 0000 -uuu uuuu table 5-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
? 2012 microchip technology inc. ds30575a-page 103 pic18f97j94 family ssp2con3 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu cm2con 64-pin 80-pin 100-pin 0001 1111 0001 1111 uuuu uuuu cm3con 64-pin 80-pin 100-pin 0001 1111 0001 1111 uuuu uuuu ccptmrs0 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ccptmrs1 64-pin 80-pin 100-pin 00-0 -000 00-0 -000 uuuu uuuu ccptmrs2 64-pin 80-pin 100-pin ---0 -000 ---0 -000 uuuu uuuu rcsta2 64-pin 80-pin 100-pin 0000 000x 0000 000x uuuu uuuu txsta2 64-pin 80-pin 100-pin 0000 0010 0000 0010 uuuu uuuu baudcon2 64-pin 80-pin 100-pin 01x0 0000 01x0 0000 uuuu uuuu spbrgh1 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rcsta3 64-pin 80-pin 100-pin 0000 000x 0000 000x uuuu uuuu txsta3 64-pin 80-pin 100-pin 0000 0010 0000 0010 uuuu uuuu baudcon3 64-pin 80-pin 100-pin 01x0 0000 01x0 0000 uuuu uuuu spbrgh3 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu spbrg3 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rcreg3 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu txreg3 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu dsconl 64-pin 80-pin 100-pin ---- -000 ---- -000 --- -uuu dsconh 64-pin 80-pin 100-pin 0-0- ---0 u-u- ---u u-u- ---u dswakel 64-pin 80-pin 100-pin 0000 0001 uuuu uuuu uuuu uuuu dswakeh 64-pin 80-pin 100-pin ---- ---0 ---- ---u ---- ---q dsgpr0 ( 6 ) 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu dsgpr1 ( 6 ) 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu dsgpr2 ( 6 ) 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu dsgpr3 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu spbrgh2 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu spbrg2 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rcreg2 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu txreg2 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu pstr2con 64-pin 80-pin 100-pin 00-0 0001 00-0 0001 uu-u uuuu pstr3con 64-pin 80-pin 100-pin 00-0 0001 00-0 0001 uu-u uuuu ssp2stat 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ssp2con1 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu table 5-3: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
pic18f97j94 family ds30575a-page 104 ? 2012 microchip technology inc. ssp2con2 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ssp2msk 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu tmr5h 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu tmr5l 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu t5con 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu t5gcon 64-pin 80-pin 100-pin 0000 0x00 0000 00x0 uuuu uuuu ccpr4h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccpr4l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccp4con 64-pin 80-pin 100-pin --00 0000 --00 0000 --uu uuuu ccpr5h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccpr5l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccp5con 64-pin 80-pin 100-pin --00 0000 --00 0000 --uu uuuu ccpr6h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccpr6l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccp6con 64-pin 80-pin 100-pin --00 0000 --00 0000 --uu uuuu ccpr7h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccpr7l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ccp7con 64-pin 80-pin 100-pin --00 0000 --00 0000 --uu uuuu tmr4 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu pr4 64-pin 80-pin 100-pin 1111 1111 uuuu uuuu uuuu uuuu t4con 64-pin 80-pin 100-pin -000 0000 -000 0000 -uuu uuuu ssp2buf 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu ssp2add 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ancfg 64-pin 80-pin 100-pin ---- -000 ---- -000 ---- -uuu dmacon2 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rcsta4 64-pin 80-pin 100-pin 0000 000x 0000 000x uuuu uuuu txsta4 64-pin 80-pin 100-pin 0000 0010 0000 0010 uuuu uuuu baudcon4 64-pin 80-pin 100-pin 01x0 0000 01x0 0000 uuuu uuuu spbrgh4 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu spbrg4 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rcreg4 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu txreg4 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ctmucon 64-pin 80-pin 100-pin 0-00 0000 0-00 0000 u-uu uuuu table 5-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
? 2012 microchip technology inc. ds30575a-page 105 pic18f97j94 family ctmucon1 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ctmucon2 64-pin 80-pin 100-pin 0000 00-- 0000 00-- uuuu uu-- ctmucon3 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu pmd0 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu pmd1 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu pmd2 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu pmd3 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu pmd4 64-pin 80-pin 100-pin 0000 00-- 0000 00-- uuuu uu-- mdcon 64-pin 80-pin 100-pin 0010 0--0 0010 0--0 uuuu u--u mdsrc 64-pin 80-pin 100-pin 0--- xxxx 0--- uuuu u--- uuuu mdcarh 64-pin 80-pin 100-pin 0xx- xxxx 0uu- uuuu uuu- uuuu mdcarl 64-pin 80-pin 100-pin 0xx- xxxx 0uu- uuuu uuu- uuuu odcon1 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu odcon2 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu trisk 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu latk 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu portk 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu trisl 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu latl 64-pin 80-pin 100-pin xxxx xxxx uuuu uuuu uuuu uuuu portl 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu memcon 64-pin 80-pin 100-pin 0-00 --00 0-00 --00 u-uu --uu refo1con 64-pin 80-pin 100-pin 0-00 0-00 u-uu u-uu u-uu u-uu refo1con1 64-pin 80-pin 100-pin ---- 0000 ---- uuuu ---- uuuu refo1con2 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu refo1con3 64-pin 80-pin 100-pin -000 0000 -uuu uuuu -uuu uuuu refo2con 64-pin 80-pin 100-pin 0-00 0-00 u-uu u-uu u-uu u-uu refo2con1 64-pin 80-pin 100-pin ---- 0000 ---- uuuu ---- uuuu refo2con2 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu refo2con3 64-pin 80-pin 100-pin -000 0000 -uuu uuuu -uuu uuuu lcdps 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcdreg 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu vlcdcon 64-pin 80-pin 100-pin 0-11 1100 u-uu uuuu u-uu uuuu lcdrefh 64-pin 80-pin 100-pin 0-00 0000 u-uu uuuu u-uu uuuu table 5-3: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
pic18f97j94 family ds30575a-page 106 ? 2012 microchip technology inc. lcdrefl 64-pin 80-pin 100-pin 0000 -000 uuuu -uuu uuuu -uuu lcdse7 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcdse6 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcdse5 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcdse4 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcdse3 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcdse2 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcdse1 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcdse0 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata63 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata62 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata61 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata60 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata59 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata58 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata57 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata56 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata55 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata54 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata53 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata52 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata51 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata50 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata49 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata48 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata47 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata46 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata45 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata44 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata43 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata42 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata41 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata40 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu table 5-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
? 2012 microchip technology inc. ds30575a-page 107 pic18f97j94 family lcddata39 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata38 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata37 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata36 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata35 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata34 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata33 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata32 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata31 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata30 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata29 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata28 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata27 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata26 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata25 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata24 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata23 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata22 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata21 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata20 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata19 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata18 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata17 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata16 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata15 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata14 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata13 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata12 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata11 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata10 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata9 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata8 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata7 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu table 5-3: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
pic18f97j94 family ds30575a-page 108 ? 2012 microchip technology inc. lcddata6 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata5 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata4 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata3 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata2 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata1 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu lcddata0 64-pin 80-pin 100-pin 0000 0000 uuuu uuuu uuuu uuuu adcon2h 64-pin 80-pin 100-pin 0000 00-- 0000 00-- uuuu uu-- adcon2l 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu adcon3h 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu adcon3l 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu adcon5h 64-pin 80-pin 100-pin 000- --00 000- --00 uuu- --uu adcon5l 64-pin 80-pin 100-pin ---- 0000 ---- 0000 ---- uuuu adchs0h 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu adchs0l 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu adcss1h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcss1l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcss0h 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu adcss0l 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu adchit1h 64-pin 80-pin 100-pin ---- --00 ---- --00 ---- --uu adchit1l 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu adchit0h 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu adchit0l 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu adctmuen1h 64-pin 80-pin 100-pin -000 0000 -000 0000 uuuu uuuu adctmuen1l 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu adctmuen0h 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu adctmuen0l 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu adcbuf25h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf25l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf24h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf24l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf23h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf23l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu table 5-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
? 2012 microchip technology inc. ds30575a-page 109 pic18f97j94 family adcbuf22h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf22l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf21h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf21l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf20h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf20l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf19h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf19l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf18h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf18l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf17h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf17l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf16h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf16l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf15h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf15l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf14h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf14l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf13h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf13l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf12h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf12l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf11h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf11l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf10h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf10l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf9h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf9l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf8h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf8l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf7h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf7l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf6h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu table 5-3: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
pic18f97j94 family ds30575a-page 110 ? 2012 microchip technology inc. adcbuf6l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf5h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf5l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf4h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf4l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf3h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf3l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf2h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf2l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf1h 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu adcbuf1l 64-pin 80-pin 100-pin xxxx xxxx xxxx xxxx uuuu uuuu ancon1 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu ancon2 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu ancon3 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr52_53 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr50_51 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr48_49 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr46_47 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr44_45 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr42_43 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr40_41 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr38_39 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr36_37 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr34_35 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr32_33 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr30_31 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr28_29 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr26_27 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr24_25 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr22_23 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr20_21 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr18_19 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr16_17 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu table 5-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
? 2012 microchip technology inc. ds30575a-page 111 pic18f97j94 family rpinr14_15 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr12_13 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr10_11 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr8_9 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr6_7 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr4_5 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr2_3 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpinr0_1 64-pin 80-pin 100-pin 1111 1111 1111 1111 uuuu uuuu rpor46 64-pin 80-pin 100-pin ---- 0000 ---- 0000 ---- uuuu rpor44_45 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor42_43 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor40_41 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor38_39 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor36_37 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor34_35 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor32_33 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor30_31 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor28_29 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor26_27 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor24_25 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor22_23 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor20_21 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor18_19 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor16_17 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor14_15 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor12_13 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor10_11 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor8_9 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor6_7 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor4_5 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor2_3 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu rpor0_1 64-pin 80-pin 100-pin 0000 0000 0000 0000 uuuu uuuu ucfg 64-pin 80-pin 100-pin 00-0 -000 00-0 -000 uu-u -uuu table 5-3: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
pic18f97j94 family ds30575a-page 112 ? 2012 microchip technology inc. uie 64-pin 80-pin 100-pin -000 0000 -000 0000 -uuu uuuu ueie 64-pin 80-pin 100-pin 0--0 0000 0--0 0000 u--u uuuu uep0 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep1 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep2 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep3 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep4 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep5 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep6 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep7 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep8 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep9 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep10 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep11 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep12 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep13 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep14 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu uep15 64-pin 80-pin 100-pin ---0 0000 ---0 0000 ---u uuuu table 5-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged; x = unknown; - = unimplemented bit, read as ? 0 ?; q = value depends on condition. shaded cells indicate that conditions do not apply for the designated device. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 5-2 for reset value for specific condition. 5: bits 7,6 are unimplemented on 64 and 80-pin devices. 6: if the v bat is always powered, the dsgpx register values will remain unchanged after the first por.
? 2012 microchip technology inc. ds30575a-page 113 pic18f97j94 family 6.0 memory organization pic18f97j94 family devices have these types of memory: ? program memory ? data ram as harvard architecture devices, the data and program memories use separate busses. this enables concurrent access of the two memory spaces. additional detailed information on the operation of the flash program memory is provided in section 7.0 ?flash program memory? . figure 6-1: memory maps for pic18f97j94 family devices note: sizes of memory areas are not to scale. sizes of program memory areas are enhanced to show detail. unimplemented read as ? 0 ? unimplemented read as ? 0 ? 000000h 1fffffh 01ffffh 00ffffh pc<20:0> stack level 1 ? stack level 31 ? ? call, callw, rcall, return, retfie, retlw, 21 user memory space on-chip memory addulnk, subulnk unimplemented read as ? 0 ? on-chip memory 007fffh unimplemented read as ? 0 ? on-chip memory 017fffh config words config words config words config words pic18fx5j94 pic18fx6j94 pic18fx6j99 pic18fx7j94 on-chip memory
pic18f97j94 family ds30575a-page 114 ? 2012 microchip technology inc. 6.1 program memory organization pic18 microcontrollers implement a 21-bit program counter that is capable of addressing a 2-mbyte program memory space. accessing a location between the upper boundary of the physically implemented memory and the 2-mbyte address will return all ? 0 ?s (a nop instruction). the entire pic18f97j94 family offers a range of on-chip flash program memory sizes, from 32 kbytes (up to 16,384 single-word instructions) to 128 kbytes (65,536 single-word instructions). ? PIC18F65J94, pic18f85j94 and pic18f95j94 ? 32 kbytes of flash memory, storing up to 16,384 single-word instructions ? pic18f66j94, pic18f86j94 and pic18f96j94 ? 64 kbytes of flash memory, storing up to 32,768 single-word instructions ? pic18f66j99, pic18f86j99 and pic18f96j99 ? 96 kbytes of flash memory, storing up to 49,152 single-word instructions ? pic18f67j94, pic18f87j94 and pic18f97j94 ? 128 kbytes of flash memory, storing up to 65,536 single-word instructions the program memory maps for individual family members are shown in figure 6-1 . 6.1.1 hard memory vectors all pic18 devices have a total of three hard-coded return vectors in their program memory space. the reset vector address is the default value to which the program counter returns on all device resets; it is located at 0000h. pic18 devices also have two interrupt vector addresses for handling high-priority and low-priority interrupts. the high-priority interrupt vector is located at 0008h and the low-priority interrupt vector is at 0018h. the locations of these vectors are shown, in relation to the program memory map, in figure 6-2 . 6.1.2 flash configuration words because pic18f97j94 family devices do not have per- sistent configuration memory, the top eight words of on-chip program memory are reserved for configuration information. on reset, the configuration information is copied into the configuration registers. the configuration words are stored in their program memory location in numerical order, starting with the lower byte of config1 at the lowest address and end- ing with the upper byte of config8. the actual addresses of the flash configuration word for devices in the pic18f97j94 family are shown in tab l e 6 - 1 . their location in the memory map is shown with the other memory vectors in figure 6-2 . additional details on the device configuration words are provided in section 28.1 ?configuration bits? . figure 6-2: hard vector for pic18f97j94 family devices table 6-1: flash configuration word for pic18f97j94 family devices device program memory (kbytes) configuration word addresses PIC18F65J94 pic18f85j94 pic18f95j94 32 7ff0h to 7fffh pic18f66j94 pic18f86j94 pic18f96j94 64 fff0h to ffffh pic18f66j99 pic18f86j99 pic18f96j99 96 17ff0h to 17fffh pic18f67j94 pic18f87j94 pic18f97j94 128 1fff0h to 1ffffh reset vector low-priority interrupt vector 0000h 0018h on-chip program memory high-priority interrupt vector 0008h 1fffffh read ? 0 ? legend: (top of memory) represents upper boundary of on-chip program memory space (see figure 6-1 for device-specific values). shaded area represents unimplemented memory. areas are not shown to scale. flash configuration words (top of memory-17) (top of memory)
? 2012 microchip technology inc. ds30575a-page 115 pic18f97j94 family 6.1.3 program counter the program counter (pc) specifies the address of the instruction to fetch for execution. the pc is 21 bits wide and contained in three separate 8-bit registers. the low byte, known as the pcl register, is both readable and writable. the high byte, or pch register, contains the pc<15:8> bits and is not directly readable or writable. updates to the pch register are performed through the pclath register. the upper byte is called pcu. this register contains the pc<20:16> bits; it is also not directly readable or writable. updates to the pcu register are performed through the pclatu register. the contents of pclath and pclatu are transferred to the program counter by any operation that writes pcl. similarly, the upper two bytes of the program counter are transferred to pclath and pclatu by an operation that reads pcl. this is useful for computed offsets to the pc (see section 6.1.6.1 ?computed goto ? ). the pc addresses bytes in the program memory. to prevent the pc from becoming misaligned with word instructions, the least significant bit of pcl is fixed to a value of ? 0 ?. the pc increments by two to address sequential instructions in the program memory. the call , rcall , goto and program branch instructions write to the program counter directly. for these instructions, the contents of pclath and pclatu are not transferred to the program counter. 6.1.4 return address stack the return address stack enables execution of any combination of up to 31 program calls and interrupts. the pc is pushed onto the stack when a call or rcall instruction is executed or an interrupt is acknowledged. the pc value is pulled off the stack on a return , retlw or a retfie instruction. the value also is pulled off the stack on addulnk and subulnk instructions, if the extended instruction set is enabled. pclatu and pclath are not affected by any of the return or call instructions. the stack operates as a 31-word by 21-bit ram and a 5-bit stack pointer, stkptr. the stack space is not part of either program or data space. the stack pointer is readable and writable and the address on the top of the stack is readable and writable through the top-of-stack special function registers. data can also be pushed to, or popped from, the stack using these registers. a call type instruction causes a push onto the stack. the stack pointer is first incremented and the location pointed to by the stack pointer is written with the contents of the pc (already pointing to the instruction following the call ). a return type instruction causes a pop from the stack. the contents of the location pointed to by the stkptr are transferred to the pc and then the stack pointer is decremented. the stack pointer is initialized to ? 00000 ? after all resets. there is no ram associated with the location corresponding to a stack pointer value of ? 00000 ?; this is only a reset value. status bits indicate if the stack is full, has overflowed or has underflowed. 6.1.4.1 top-of-stack access only the top of the return address stack (tos) is readable and writable. a set of three registers, tosu:tosh:tosl, holds the contents of the stack location pointed to by the stkptr register ( figure 6-3 ). this allows users to implement a software stack, if necessary. after a call , rcall or interrupt (or addulnk and subulnk instructions, if the extended instruction set is enabled), the software can read the pushed value by reading the tosu:tosh:tosl regis- ters. these values can be placed on a user-defined software stack. at return time, the software can return these values to tosu:tosh:tosl and do a return. while accessing the stack, users must disable the global interrupt enable bits to prevent inadvertent stack corruption. figure 6-3: return address stack and associated registers 00011 001a34h 11111 11110 11101 00010 00001 00000 00010 return address stack <20:0> to p - o f - st a c k 000d58h tosl tosh tosu 34h 1ah 00h stkptr<4:0> top-of-stack registers stack pointer
pic18f97j94 family ds30575a-page 116 ? 2012 microchip technology inc. 6.1.4.2 return stack pointer (stkptr) the stkptr register ( register 6-1 ) contains the stack pointer value, the stkful (stack full) status bit and the stkunf (stack underflow) status bits. the value of the stack pointer can be 0 through 31. the stack pointer increments before values are pushed onto the stack and decrements after values are popped off the stack. on reset, the stack pointer value will be zero. the user may read and write the stack pointer value. this feature can be used by a real-time operating system (rtos) for return-stack maintenance. after the pc is pushed onto the stack, 31 times (without popping any values off the stack), the stkful bit is set. the stkful bit is cleared by software or by a por. what happens when the stack becomes full depends on the state of the stvren (stack overflow reset enable) configuration bit. (for a description of the device configuration bits, see section 28.1 ?configu- ration bits? .) if stvren is set (default), the 31st push will push the (pc + 2) value onto the stack, set the stkful bit and reset the device. the stkful bit will remain set and the stack pointer will be set to zero. if stvren is cleared, the stkful bit will be set on the 31st push and the stack pointer will increment to 31. any additional pushes will not overwrite the 31st push and the stkptr will remain at 31. when the stack has been popped enough times to unload the stack, the next pop will return a value of zero to the pc and set the stkunf bit, while the stack pointer remains at zero. the stkunf bit will remain set until cleared by software or until a por occurs. 6.1.4.3 push and pop instructions since the top-of-stack is readable and writable, the ability to push values onto the stack and pull values off the stack, without disturbing normal program execu- tion, is a desirable feature. the pic18 instruction set includes two instructions, push and pop , that permit the tos to be manipulated under software control. tosu, tosh and tosl can be modified to place data or a return address on the stack. the push instruction places the current pc value onto the stack. this increments the stack pointer and loads the current pc value onto the stack. the pop instruction discards the current tos by decrementing the stack pointer. the previous value pushed onto the stack then becomes the tos value. note: returning a value of zero to the pc on an underflow has the effect of vectoring the program to the reset vector, where the stack conditions can be verified and appropriate actions can be taken. this is not the same as a reset, as the contents of the sfrs are not affected. register 6-1: stkptr: stack pointer register r/c-0 r/c-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 stkful ( 1 ) stkunf ( 1 ) ? sp4 sp3 sp2 sp1 sp0 bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 stkful: stack full flag bit ( 1 ) 1 = stack has become full or overflowed 0 = stack has not become full or overflowed bit 6 stkunf: stack underflow flag bit ( 1 ) 1 = stack underflow has occurred 0 = stack underflow did not occur bit 5 unimplemented: read as ? 0 ? bit 4-0 sp<4:0>: stack pointer location bits note 1: bit 7 and bit 6 are cleared by user software or by a por.
? 2012 microchip technology inc. ds30575a-page 117 pic18f97j94 family 6.1.4.4 stack full and underflow resets device resets on stack overflow and stack underflow conditions are enabled by setting the stvren bit (config1l<5>). when stvren is set, a full or under- flow condition will set the appropriate stkful or stkunf bit and then cause a device reset. when stvren is cleared, a full or underflow condition will set the appropriate stkful or stkunf bit, but not cause a device reset. the stkful or stkunf bits are cleared by user software or a power-on reset. 6.1.5 fast register stack a fast register stack is provided for the status, wreg and bsr registers to provide a ?fast return? option for interrupts. this stack is only one level deep and is neither readable nor writable. it is loaded with the current value of the corresponding register when the processor vectors for an interrupt. all interrupt sources will push values into the stack registers. the values in the registers are then loaded back into the working registers if the retfie , fast instruction is used to return from the interrupt. if both low and high-priority interrupts are enabled, the stack registers cannot be used reliably to return from low-priority interrupts. if a high-priority interrupt occurs while servicing a low-priority interrupt, the stack register values stored by the low-priority interrupt will be overwritten. in these cases, users must save the key registers in software during a low-priority interrupt. if interrupt priority is not used, all interrupts may use the fast register stack for returns from interrupt. if no interrupts are used, the fast register stack can be used to restore the status, wreg and bsr registers at the end of a subroutine call. to use the fast register stack for a subroutine call, a call label , fast instruction must be executed to save the status, wreg and bsr registers to the fast register stack. a return , fast instruction is then executed to restore these registers from the fast register stack. example 6-1 shows a source code example that uses the fast register stack during a subroutine call and return. example 6-1: fast register stack code example 6.1.6 look-up tables in program memory there may be programming situations that require the creation of data structures, or look-up tables, in program memory. for pic18 devices, look-up tables can be implemented in two ways: ? computed goto ? table reads 6.1.6.1 computed goto a computed goto is accomplished by adding an offset to the program counter. an example is shown in example 6-2 . a look-up table can be formed with an addwf pcl instruction and a group of retlw nn instructions. the w register is loaded with an offset into the table before executing a call to that table. the first instruction of the called routine is the addwf pcl instruction. the next instruction executed will be one of the retlw nn instructions that returns the value, ? nn ?, to the calling function. the offset value (in wreg) specifies the number of bytes that the program counter should advance and should be multiples of two (lsb = 0 ). in this method, only one data byte may be stored in each instruction location and room on the return address stack is required. example 6-2: computed goto using an offset value 6.1.6.2 table reads a better method of storing data in program memory allows two bytes of data to be stored in each instruction location. look-up table data may be stored, two bytes per program word, while programming. the table pointer (tblptr) specifies the byte address and the table latch (tablat) contains the data that is read from the program memory. data is transferred from program memory one byte at a time. the table read operation is discussed further in section 7.1 ?table reads and table writes? . call sub1, fast ;status, wreg, bsr ;saved in fast register ;stack ? ? sub1 ? ? return fast ;restore values saved ;in fast register stack movf offset, w call table org nn00h table addwf pcl retlw nnh retlw nnh retlw nnh . . .
pic18f97j94 family ds30575a-page 118 ? 2012 microchip technology inc. 6.2 pic18 instruction cycle 6.2.1 clocking scheme the microcontroller clock input, whether from an internal or external source, is internally divided by four to generate four non-overlapping quadrature clocks (q1, q2, q3 and q4). internally, the program counter is incremented on every q1, with the instruction fetched from the program memory and latched into the instruction register (ir) during q4. the instruction is decoded and executed during the following q1 through q4. the clocks and instruction execution flow are shown in figure 6-4 . 6.2.2 instruction flow/pipelining an ?instruction cycle? consists of four q cycles, q1 through q4. the instruction fetch and execute are pipe- lined in such a manner that a fetch takes one instruction cycle, while the decode and execute take another instruction cycle. however, due to the pipelining, each instruction effectively executes in one cycle. if an instruction (such as goto ) causes the program coun- ter to change, two cycles are required to complete the instruction. (see example 6-3 .) a fetch cycle begins with the program counter (pc) incrementing in q1. in the execution cycle, the fetched instruction is latched into the instruction register (ir) in cycle q1. this instruction is then decoded and executed during the q2, q3 and q4 cycles. data memory is read during q2 (operand read) and written during q4 (destination write). figure 6-4: clock/ instruction cycle example 6-3: instruction pipeline flow q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 q1 q2 q3 q4 pc osc2/clko (rc mode) pc pc + 2 pc + 4 fetch inst (pc) execute inst (pc ? 2) fetch inst (pc + 2) execute inst (pc) fetch inst (pc + 4) execute inst (pc + 2) internal phase clock all instructions are single cycle, except for any program branches. these take two cycles since the fetch instruction is ?flushed? from the pipeline while the new instruction is being fetched and then executed. t cy 0t cy 1t cy 2t cy 3t cy 4t cy 5 1. movlw 55h fetch 1 execute 1 2. movwf portb fetch 2 execute 2 3. bra sub_1 fetch 3 execute 3 4. bsf porta, bit3 (forced nop) fetch 4 flush ( nop ) 5. instruction @ address sub_1 fetch sub_1 execute sub_1
? 2012 microchip technology inc. ds30575a-page 119 pic18f97j94 family 6.2.3 instructions in program memory the program memory is addressed in bytes. instruc- tions are stored as two or four bytes in program memory. the least significant byte of an instruction word is always stored in a program memory location with an even address (lsb = 0 ). to maintain alignment with instruction boundaries, the pc increments in steps of two and the lsb will always read ? 0 ? (see section 6.1.3 ?program counter? ). figure 6-5 shows an example of how instruction words are stored in the program memory. the call and goto instructions have the absolute program memory address embedded into the instruc- tion. since instructions are always stored on word boundaries, the data contained in the instruction is a word address. the word address is written to pc<20:1> which accesses the desired byte address in program memory. instruction #2 in figure 6-5 shows how the instruction, goto 0006h , is encoded in the program memory. program branch instructions, which encode a relative address offset, operate in the same manner. the offset value stored in a branch instruction represents the number of single-word instructions that the pc will be offset by. for more details on the instruction set, see section 29.0 ?instruction set summary? . figure 6-5: instructions in program memory 6.2.4 two-word instructions the standard pic18 instruction set has four, two-word instructions: call , movff , goto and lsfr . in all cases, the second word of the instructions always has ? 1111 ? as its four most significant bits. the other 12 bits are literal data, usually a data memory address. the use of ? 1111 ? in the 4 msbs of an instruction specifies a special form of nop . if the instruction is executed in proper sequence, immediately after the first word, the data in the second word is accessed and used by the instruction sequence. if the first word is skipped, for some reason, and the second word is executed by itself, a nop is executed instead. this is necessary for cases when the two-word instruction is preceded by a conditional instruction that changes the pc. example 6-4 shows how this works. example 6-4: two- word instructions word address lsb = 1 lsb = 0 ? program memory byte locations ? ? 000000h 000002h 000004h 000006h instruction 1: movlw 055h 0fh 55h 000008h instruction 2: goto 0006h efh 06h 00000ah f0h 00h 00000ch instruction 3: movff 123h, 456h c1h 23h 00000eh f4h 56h 000010h 000012h 000014h note: for information on two-word instructions in the extended instruction set, see section 6.5 ?program memory and the extended instruction set? . case 1: object code source code 0110 0110 0000 0000 tstfsz reg1 ; is ram location 0? 1100 0001 0010 0011 movff reg1, reg2 ; no, skip this word 1111 0100 0101 0110 ; execute this word as a nop 0010 0100 0000 0000 addwf reg3 ; continue code case 2: object code source code 0110 0110 0000 0000 tstfsz reg1 ; is ram location 0? 1100 0001 0010 0011 movff reg1, reg2 ; yes, execute this word 1111 0100 0101 0110 ; 2nd word of instruction 0010 0100 0000 0000 addwf reg3 ; continue code
pic18f97j94 family ds30575a-page 120 ? 2012 microchip technology inc. 6.3 data memory organization the data memory in pic18 devices is implemented as static ram. each register in the data memory has a 12-bit address, allowing up to 4,096 bytes of data memory. the memory space is divided into as many as 16 banks that contain 256 bytes each. pic18f97j94 family devices implement all 16 banks, for a total of 4kbytes. figure 6-6 and figure 6-7 show the data memory organization for the devices. the data memory contains special function registers (sfrs) and general purpose registers (gprs). the sfrs are used for control and status of the controller and peripheral functions, while gprs are used for data storage and scratchpad operations in the user?s application. any read of an unimplemented location will read as ? 0 ?s. the instruction set and architecture allow operations across all banks. the entire data memory may be accessed by direct, indirect or indexed addressing modes. addressing modes are discussed later in this section. to ensure that commonly used registers (select sfrs and select gprs) can be accessed in a single cycle, pic18 devices implement an access bank. this is a 256-byte memory space that provides fast access to select sfrs and the lower portion of gpr bank 0 with- out using the bank select register. for details on the access ram, see section 6.3.2 ?access bank? . 6.3.1 bank select register large areas of data memory require an efficient addressing scheme to make it possible for rapid access to any address. ideally, this means that an entire address does not need to be provided for each read or write operation. for pic18 devices, this is accom- plished with a ram banking scheme. this divides the memory space into 16 contiguous banks of 256 bytes. depending on the instruction, each location can be addressed directly by its full 12-bit address, or an eight-bit, low-order address and a four-bit bank pointer. most instructions in the pic18 instruction set make use of the bank pointer, known as the bank select register (bsr). this sfr holds the four most significant bits of a location?s address. the instruction itself includes the eight least significant bits. only the four lower bits of the bsr are implemented (bsr<3:0>). the upper four bits are unused, always read as ? 0 ? and cannot be written to. the bsr can be loaded directly by using the movlb instruction. the value of the bsr indicates the bank in data memory. the eight bits in the instruction show the loca- tion in the bank and can be thought of as an offset from the bank?s lower boundary. the relationship between the bsr?s value and the bank division in data memory is shown in figure 6-7 . since up to 16 registers may share the same low-order address, the user must always be careful to ensure that the proper bank is selected before performing a data read or write. for example, writing what should be program data to an eight-bit address of f9h, while the bsr is 0fh, will end up resetting the program counter. while any bank can be selected, only those banks that are actually implemented can be read or written to. writes to unimplemented banks are ignored, while reads from unimplemented banks will return ? 0 ?s. even so, the status register will still be affected as if the operation was successful. the data memory map in figure 6-6 indicates which banks are implemented. in the core pic18 instruction set, only the movff instruction fully specifies the 12-bit address of the source and target registers. when this instruction executes, it ignores the bsr completely. all other instructions include only the low-order address as an operand and must use either the bsr or the access bank to locate their target registers. note: the operation of some aspects of data memory are changed when the pic18 extended instruction set is enabled. see section 6.6 ?data memory and the extended instruction set? for more information.
? 2012 microchip technology inc. ds30575a-page 121 pic18f97j94 family figure 6-6: data memory map fo r pic18f97j94 family devices 00h 5fh 60h ffh access bank when a = 0 : the bsr is ignored and the access bank is used. the first 96 bytes are general purpose ram (from bank 0). the second 160 bytes are special function registers (from bank 15). when a = 1 : the bsr specifies the bank used by the instruction. access ram high access ram low (sfrs) bank 0 bank 1 bank 14 bank 15 data memory map bsr<3:0> = 0000 = 0001 = 1111 060h 05fh f60h fffh f5fh f00h effh 1ffh 100h 0ffh 000h access ram ffh 00h ffh 00h ffh 00h gpr gpr sfr bank 2 = 0010 2ffh 200h bank 3 ffh 00h gpr ffh = 0011 gpr gpr gpr gpr gpr 4ffh 400h 5ffh 500h 3ffh 300h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h 00h = 0110 = 0111 = 0101 = 0100 bank 4 bank 5 bank 6 bank 7 bank 8 = 1110 6ffh 600h 7ffh 700h 800h bank 9 bank 10 bank 11 bank 12 bank 13 8ffh 900h 9ffh a00h affh b00h bffh c00h cffh d00h dffh e00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h sfr gpr gpr gpr gpr gpr gpr note 1: addresses, dfah through f5fh, are also sfrs, but are not part of the access ram. users must always use the complete address, or load the proper bsr value, to access these registers. = 1000 = 1001 = 1010 = 1011 = 1100 = 1101 fah sfr dfah
pic18f97j94 family ds30575a-page 122 ? 2012 microchip technology inc. figure 6-7: use of the bank select register (direct addressing) 6.3.2 access bank while the use of the bsr, with an embedded 8-bit address, allows users to address the entire range of data memory, it also means that the user must ensure that the correct bank is selected. if not, data may be read from, or written to, the wrong location. this can be disastrous if a gpr is the intended target of an operation, but an sfr is written to instead. verifying and/or changing the bsr for each read or write to data memory can become very inefficient. to streamline access for the most commonly used data memory locations, the data memory is configured with an access bank, which allows users to access a mapped block of memory without specifying a bsr. the access bank consists of the first 96 bytes of memory (00h-5fh) in bank 0 and the last 160 bytes of memory (60h-ffh) in bank 15. the lower half is known as the ?access ram? and is composed of gprs. the upper half is where the device?s sfrs are mapped. these two areas are mapped contiguously in the access bank and can be addressed in a linear fashion by an eight-bit address ( figure 6-6 ). the access bank is used by core pic18 instructions that include the access ram bit (the ?a? parameter in the instruction). when ?a? is equal to ? 1 ?, the instruction uses the bsr and the 8-bit address included in the opcode for the data memory address. when ?a? is ? 0 ?, however, the instruction is forced to use the access bank address map. in that case, the current value of the bsr is ignored entirely. using this ?forced? addressing allows the instruction to operate on a data address in a single cycle without updating the bsr first. for 8-bit addresses of 60h and above, this means that users can evaluate and operate on sfrs more efficiently. the access ram below 60h is a good place for data values that the user might need to access rapidly, such as immediate computational results or common program variables. access ram also allows for faster and more code efficient context saving and switching of variables. the mapping of the access bank is slightly different when the extended instruction set is enabled (xinst configuration bit = 1 ). this is discussed in more detail in section 6.6.3 ?mapping the access bank in indexed literal offset mode? . 6.3.3 general purpose register file pic18 devices may have banked memory in the gpr area. this is data ram which is available for use by all instructions. gprs start at the bottom of bank 0 (address 000h) and grow upwards towards the bottom of the sfr area. gprs are not initialized by a power-on reset and are unchanged on all other resets. note 1: the access ram bit of the instruction can be used to force an override of the selected bank (bsr<3:0>) to the registers of the access bank. 2: the movff instruction embeds the entire 12-bit address in the instruction. data memory bank select (2) 7 0 from opcode (2) 0000 000h 100h 200h 300h f00h e00h fffh bank 0 bank 1 bank 2 bank 14 bank 15 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh bank 3 through bank 13 0010 1 7 0 bsr (1) 1111111
? 2012 microchip technology inc. ds30575a-page 123 pic18f97j94 family 6.3.4 special function registers the special function registers (sfrs) are registers used by the cpu and peripheral modules for controlling the desired operation of the device. these registers are implemented as static ram. sfrs start at the top of data memory (fffh) and extend downward to occupy all of bank 15 (f00h to fffh), bank 14 (e00h to effh) and part of bank 13 (dfah to dffh). a list of these registers is given in table 6-2 . the sfrs can be classified into two sets: those associated with the ?core? device functionality (alu, resets and interrupts) and those related to the peripheral functions. the reset and interrupt registers are described in their respective chapters, while the alu?s status register is described later in this section. registers related to the operation of the peripheral features are described in t he chapter for that peripheral. the sfrs are typically distributed among the peripherals whose functions they control. unused sfr locations are unimplemented and read as ? 0 ?s.
pic18f97j94 family ds30575a-page 124 ? 2012 microchip technology inc. table 6-2: register file summary file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 fffh tosu ? ? ? top-of-stack upper byte (tos<20:16>) ffeh tosh top-of-stack high byte (tos<15:8>) ffdh tosl top-of-stack low byte (tos<7:0>) ffch stkptr stkful stkunf ?stkptr ffbh pclatu ? ? ? holding register for pc<20:16> ffah pclath holding register for pc<15:8> ff9h pcl pc low byte (pc<7:0>) ff8h tblptru ? ? acss program memory table pointer upper byte (tblptr<20:16>) ff7h tblptrh program memory table pointer high byte (tblptr<15:8>) ff6h tblptrl program memory table pointer low byte (tblptr<7:0>) ff5h tablat program memory table latch ff4h prodh product register high byte ff3h prodl product register low byte ff2h intcon gie/gieh peie/giel tmr0ie int0ie iocie tmr0if int0if iocif ff1h intcon2 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip iocip ff0h intcon3 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if fefh indf0 uses contents of fsr0 to address data memory ? value of fsr0 not changed (not a physical register) feeh postinc0 uses contents of fsr0 to address data memory ? value of fsr0 post-incremented (not a physical register) fedh postdec0 uses contents of fsr0 to address data memory ? value of fsr0 post-decremented (not a physical register) fech preinc0 uses contents of fsr0 to address data memory ? value of fsr0 pre-incremented (not a physical register) febh plusw0 uses contents of fsr0 to address data memory ? value of fsr0 pre-incremented (not a physical register) ? value of fsr0 offset by w feah fsr0h ? ? ? ? indirect data memory address pointer 0 high fe9h fsr0l indirect data memory address pointer 0 low byte fe8h wreg working register fe7h indf1 uses contents of fsr1 to address data memory ? value of fsr1 not changed (not a physical register) fe6h postinc1 uses contents of fsr1 to address data memory ? value of fsr1 post-incremented (not a physical register) fe5h postdec1 uses contents of fsr1 to address data memory ? value of fsr1 post-decremented (not a physical register) fe4h preinc1 uses contents of fsr1 to address data memory ? value of fsr1 pre-incremented (not a physical register) fe3h plusw1 uses contents of fsr1 to address data memory ? value of fsr1 pre-incremented (not a physical register) ? value of fsr1 offset by w fe2h fsr1h ? ? ? ? indirect data memory address pointer 1 high fe1h fsr1l indirect data memory address pointer 1 low byte fe0h bsr ? ? ? ? bank select register fdfh indf2 uses contents of fsr2 to address data memory ? value of fsr2 not changed (not a physical register) fdeh postinc2 uses contents of fsr2 to address data memory ? value of fsr2 post-incremented (not a physical register) fddh postdec2 uses contents of fsr2 to address data memory ? value of fsr2 post-decremented (not a physical register) fdch preinc2 uses contents of fsr2 to address data memory ? value of fsr2 pre-incremented (not a physical register) fdbh plusw2 uses contents of fsr2 to address data memory ? value of fsr2 pre-incremented (not a physical register) ? value of fsr2 offset by w fdah fsr2h ? ? ? ? indirect data memory address pointer 2 high fd9h fsr2l indirect data memory address pointer 2 low byte fd8h status ? ? ?n ov zdcc fd7h tmr0h timer0 register high byte fd6h tmr0l timer0 register low byte fd5h t0con tmr0on t08bit t0cs1 t0cs0 psa t0ps2 t0ps1 t0ps0 fd4h unimplemented ? ? ? ? ? ? ? ? fd3h osccon idlen cosc2 cosc1 cosc0 ? nosc2 nosc1 nosc0 fd2h ipr5 ? actorsip actlockip tmr8ip ? tmr6ip tmr5ip tmr4ip fd1h iocf iocf7 iocf6 iocf5 iocf4 iocf3 iocf2 iocf1 iocf0 fd0h rcon ipen ?cm ri to pd por bor legend: ? = unimplemented, read as ? 0 ?.
? 2012 microchip technology inc. ds30575a-page 125 pic18f97j94 family fcfh tmr1h timer1 register high byte fceh tmr1l timer1 register low byte fcdh t1con tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 soscen t1sync rd16 tmr1on fcch tmr2 timer2 register fcbh pr2 timer2 period register fcah t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 fc9h ssp1buf mssp1 receive buffer/transmit register fc8h ssp1add mssp1 address register in i 2 c? slave mode. mssp1 baud rate reload register in i 2 c master mode. fc7h ssp1stat smp cke d/a psr/w ua bf fc6h ssp1con1 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 fc5h ssp1con2 gcen ackstat ackdt acken rcen pen rsen sen fc4h cmstat ? ? ? ? ? c3out c2out c1out fc3h adcbuf0h a/d result register 0 high byte fc2h adcbuf0l a/d result register 0 low byte fc1h adcon1h adon ? ? ? ? mode12 form1 form0 fc0h adcon1l ssrc3 ssrc2 ssrc1 ssrc0 ? asam samp done fbfh cvrconh ? ? ? cvr4 cvr3 cvr2 cvr1 cvr0 fbeh cvrconl cvren cvroe cvrpss1 cvrpss0 ? ? ? cvrnss fbdh eccp1as eccp1ase eccp1as2 eccp1as1 eccp1as0 pss1ac1 pss1ac0 pss1bd1 pss1bd0 fbch eccp1del p1rsen p1dc6 p1dc5 p1dc4 p1dc3 p1dc2 p1dc1 p1dc0 fbbh ccpr1h capture/compare/pwm register1 high byte fbah ccpr1l capture/compare/pwm register1 low byte fb9h ccp1con p1m1 p1m0 ccp1x ccp 1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 fb8h pir5 ? actorsif actlockif tmr8if ? tmr6if tmr5if tmr4if fb7h pie5 ? actorsie actlockie tmr8ie ? tmr6ie tmr5ie tmr4ie fb6h ipr4 ccp10ip ccp9ip ccp8ip ccp7ip ccp6ip ccp5ip ccp4ip eccp3ip fb5h pir4 ccp10if ccp9if ccp8if ccp 7if ccp6if ccp5if ccp4if eccp3if fb4h pie4 ccp10ie ccp9ie ccp8ie ccp7ie ccp6ie ccp5ie ccp4ie eccp3ie fb3h tmr3h timer3 register high byte fb2h tmr3l timer3 register low byte fb1h t3con tmr3cs1 tmr3cs0 t3ckps1 t3ckps0 soscen t3sync rd16 tmr3on fb0h t3gcon tmr3ge t3gpol t3gtm t3gspm t3ggo/t3 don e t3gval t3gss1 t3gss0 fafh spbrg1 eusart1 baud rate generator faeh rcreg1 eusart1 receive register fadh txreg1 eusart1 transmit register fach txsta1 csrc tx9 txen sync sendb brgh trmt tx9d fabh rcsta1 spen rx9 sren cren adden ferr oerr rx9d faah t1gcon tmr1ge t1gpol t1gtm t1gspm t1ggo/t1 don e t1gval t1gss1 t1gss0 fa9h ipr6 rc4ip tx4ip rc3ip tx3ip ? cmp3ip cmp2ip cmp1ip fa8h hlvdcon vdirmag bgvst irvst hlvden hlvdl3 hlvdl2 hlvdl1 hlvdl0 fa7h pspcon ibf obf ibov pspmode ? ? ? ? fa6h pir6 rc4if tx4if rc3if tx3if ? cmp3if cmp2if cmp1if fa5h ipr3 tmr5gip lcdip rc2ip tx2ip ctmuip ccp2ip ccp1ip rtccip fa4h pir3 tmr5gif lcdif rc2if tx2if ctmuif ccp2if ccp1if rtccif fa3h pie3 tmr5gie lcdie rc2ie tx2ie ctmuie ccp2ie ccp1ie rtccie fa2h ipr2 oscfip ssp2ip bcl2ip usbip bcl1ip hlvdip tmr3ip tmr3gip fa1h pir2 oscfif ssp2if bcl2if usbif bcl1if hlvdif tmr3if tmr3gif fa0h pie2 oscfie ssp2ie bcl2ie usbie bcl1ie hlvdie tmr3ie tmr3gie f9fh ipr1 pspip adip rc1ip tx1ip ssp1ip tmr1gip tmr2ip tmr1ip f9eh pir1 pspif adif rc1if tx1if ssp1if tmr1gif tmr2if tmr1if f9dh pie1 pspie adie rc1ie tx1ie ssp1ie tmr1gie tmr2ie tmr1ie table 6-2: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 legend: ? = unimplemented, read as ? 0 ?.
pic18f97j94 family ds30575a-page 126 ? 2012 microchip technology inc. f9ch pstr1con cmpl1 cmpl0 ? strsync strd strc strb stra f9bh osctune ? ? tun5 tun4 tun3 tun2 tun1 tun0 f9ah trisj trisj7 trisj6 trisj5 trisj4 trisj3 trisj2 trisj1 trisj0 f99h trish trish7 trish6 trish5 trish4 trish3 trish2 trish1 trish0 f98h trisg trisg7 trisg6 ? trisg4 trisg3 trisg2 trisg1 trisg0 f97h trisf trisf7 trisf6 trisf5 trisf4 trisf3 trisf2 ? ? f96h trise trise7 trise6 trise5 trise4 trise3 trise2 trise1 trise0 f95h trisd trisd7 trisd6 trisd5 trisd4 trisd3 trisd2 trisd1 trisd0 f94h trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 f93h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 f92h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 f91h latj latj7 latj6 latj5 latj4 latj3 latj2 latj1 latj0 f90h lath lath7 lath6 lath5 lath4 lath3 lath2 lath1 lath0 f8fh latg latg7 latg6 ? latg4 latg3 latg2 latg1 latg0 f8eh latf latf7 latf6 latf5 latf4 latf3 latf2 ? ? f8dh late late7 late6 late5 late4 late3 late2 late1 late0 f8ch latd latd7 latd6 latd5 latd4 latd3 latd2 latd1 latd0 f8bh latc latc7 latc6 latc5 latc4 latc3 latc2 latc1 latc0 f8ah latb latb7 latb6 latb5 latb4 latb3 latb2 latb1 latb0 f89h lata lata7 lata6 lata5 lata4 lata3 lata2 lata1 lata0 f88h portj rj7 rj6 rj5 rj4 rj3 rj2 rj1 rj0 f87h porth rh7 rh6 rh5 rh4 rh3 rh2 rh1 rh0 f86h portg rg7 rg6 ? rg4 rg3 rg2 rg1 rg0 f85h portf rf7 rf6 rf5 rf4 rf3 rf2 ? ? f84h porte re7 re6 re5 re4 re3 re2 re1 re0 f83h portd rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 f82h portc rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 f81h portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 f80h porta ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 f7fh eecon1 ? ? wwprog free wrerr wren wr ? f7eh eecon2 eeprom control register 2 (not a physical register) f7dh rcon2 extr ?swdten ? ? ? ? ? f7ch rcon3 stkerr ? ? ? vddbor vddpor vbpor vbat f7bh rcon4 ? ? ?sreten ?dpslp ?pmslp f7ah ufrml frm7 frm6 frm5 frm4 frm3 frm2 frm1 frm0 f79h ufrmh ? ? ? ? ? frm10 frm9 frm8 f78h uir ? sofif stallif idleif trnif actvif uerrif urstif f77h ueir btsef ? ? btoef dfn8ef crc16ef crc5ef pidef f76h ustat ? endp3 endp2 endp1 endp0 dir ppbi ? f75h ucon ? ppbrst se0 pktdis usben resume suspnd ? f74h uaddr ? addr6 addr5 addr4 addr3 addr2 addr1 addr0 f73h trisvp trisvp7 trisvp6 trisvp5 trisvp4 trisvp3 trisvp2 trisvp1 trisvp0 f72h latvp latvp7 latvp6 latvp5 latvp4 latvp3 latvp2 latvp1 latvp0 f71h portvp rvp7 rvp6 rvp5 rvp4 rvp3 rvp2 rvp1 rvp0 f70h txaddrl spi dma transmit data pointer low byte f6fh txaddrh ? ? ? ? spi dma transmit data pointer high byte f6eh rxaddrl spi dma receive data pointer low byte f6dh rxaddrh ? ? ? ? spi dma receive data pointer high byte f6ch dmabcl spi dma byte count low byte f6bh dmabch ? ? ? ? ? ? spi dma byte count high byte f6ah txbuf txbuf7 txbuf6 txbuf5 txbuf4 txbuf3 txbuf2 txbuf1 txbuf0 table 6-2: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 legend: ? = unimplemented, read as ? 0 ?.
? 2012 microchip technology inc. ds30575a-page 127 pic18f97j94 family f69h ssp1con3 acktim pcie scie boen sdaht sbcde ahen dhen f68h ssp1msk msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 f67h baudcon1 abdovf rcidl rxdtp txckp brg16 iren wue abden f66h osccon2 clklock iolock lock ? cf poscen soscgo ? f65h osccon3 ? ? ? ? ? ircf2 ircf1 ircf0 f64h osccon4 cpdiv1 cpdiv0 pllen ? ? ? ? ? f63h actcon acten ? actsidl actsrc actlock actlockpol actors actorspol f62h wpub wpub7 wpub6 wpub5 wpub4 wpub3 wpub2 wpub1 wpub0 f61h pie6 rc4ie tx4ie rc3ie tx3ie ? cmp3ie cmp2ie cmp1ie f60h dmacon1 sscon1 sscon0 txinc rxinc duplex1 duplex0 dlyinten dmaen f5fh rtccon1 rtcen ? rtcwren rtcsync halfsec rtcoe rtcptr1 rtcptr0 f5eh rtccal cal7 cal6 cal5 cal4 cal3 cal2 cal1 cal0 f5dh rtcvalh rtcc value high register window based on rtcptr<1:0> f5ch rtcvall rtcc value low register window based on rtcptr<1:0> f5bh alrmcfg alrmen chime amask3 amask2 amask1 amask0 alrmptr1 alrmptr0 f5ah alrmrpt arpt7 arpt6 arpt5 arpt4 arpt3 arpt2 arpt1 arpt0 f59h alrmvalh alarm value high register window based on aptr<1:0> f58h alrmvall alarm value low register window based on aptr<1:0> f57h rtccon2 pwcen pwcpol pwccpre pwcspre rtcclksel1 rtcclksel0 rtcsecsel1 rtcsecsel0 f56h iocp iocp7 iocp6 iocp5 iocp4 iocp3 iocp2 iocp1 iocp0 f55h iocn iocn7 iocn6 iocn5 iocn4 iocn3 iocn2 iocn1 iocn0 f54h padcfg1 rdpu repu rfpu rgpu rhpu rjpu rkpu rlpu f53h cm1con con coe cpol evpol1 evpol0 cref cch1 cch0 f52h eccp2as eccp2ase eccp2as2 eccp2as1 eccp2as0 pss2ac1 pss2ac0 pss2bd1 pss2bd0 f51h eccp2del p2rsen p2dc6 p2dc5 p2dc4 p2dc3 p2dc2 p2dc1 p2dc0 f50h ccpr2h capture/compare/pwm register 1 high byte f4fh ccpr2l capture/compare/pwm register 1 low byte f4eh ccp2con p2m1 p2m0 ccp2x ccp 2y ccp2m3 ccp2m2 ccp2m1 ccp2m0 f4dh eccp3as eccp3ase eccp3as2 eccp3as1 eccp3as0 pss3ac1 pss3ac0 pss3bd1 pss3bd0 f4ch eccp3del p3rsen p3dc6 p3dc5 p3dc4 p3dc3 p3dc2 p3dc1 p3dc0 f4bh ccpr3h capture/compare/pwm register 1 high byte f4ah ccpr3l capture/compare/pwm register 1 low byte f49h ccp3con p3m1 p3m0 ccp3x ccp 3y ccp3m3 ccp3m2 ccp3m1 ccp3m0 f48h ccpr8h capture/compare/pwm register 8 high byte f47h ccpr8l capture/compare/pwm register 8 low byte f46h ccp8con ? ? ccp8x ccp8y ccp8m3 ccp 8m2 ccp8m1 ccp8m0 f45h ccpr9h capture/compare/pwm register 9 high byte f44h ccpr9l capture/compare/pwm register 9 low byte f43h ccp9con ? ? ccp9x ccp9y ccp9m3 ccp 9m2 ccp9m1 ccp9m0 f42h ccpr10h capture/compare/pwm register 10 high byte f41h ccpr10l capture/compare/pwm register 10 low byte f40h ccp10con ? ? ccp10x ccp10y ccp10m3 ccp10m2 ccp10m1 ccp10m0 f3fh tmr6 timer6 register f3eh pr6 timer6 period register f3dh t6con ? t6outps3 t6outps2 t6outps1 t6outps0 tmr6on t6ckps1 t6ckps0 f3ch tmr8 timer8 register f3bh pr8 timer8 period register f3ah t8con ? t8outps3 t8outps2 t8outps1 t8outps0 tmr8on t8ckps1 t8ckps0 f39h ssp2con3 acktim pcie scie boen sdaht sbcde ahen dhen f38h cm2con con coe cpol evpol1 evpol0 cref cch1 cch0 f37h cm3con con coe cpol evpol1 evpol0 cref cch1 cch0 table 6-2: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 legend: ? = unimplemented, read as ? 0 ?.
pic18f97j94 family ds30575a-page 128 ? 2012 microchip technology inc. f36h ccptmrs0 c3tsel1 c3tsel0 c2tsel2 c2tsel1 c2tsel0 c1tsel2 c1tsel1 c1tsel0 f35h ccptmrs1 c7tsel1 c7tsel0 ? c6tsel0 ? c5tsel0 c4tsel1 c4tsel0 f34h ccptmrs2 ? ? ?c10tsel0 ? c9tsel0 c8tsel1 c8tsel0 f33h rcsta2 spen rx9 sren cren adden ferr oerr rx9d f32h txsta2 csrc tx9 txen sync sendb brgh trmt tx9d f31h baudcon2 abdovf rcidl rxdtp txckp brg16 iren wue abden f30h spbrgh1 eusart1 baud rate generator high byte f2fh rcsta3 spen rx9 sren cren adden ferr oerr rx9d f2eh txsta3 csrc tx9 txen sync sendb brgh trmt tx9d f2dh baudcon3 abdovf rcidl rxdtp txckp brg16 iren wue abden f2ch spbrgh3 eusart3 baud rate generator high byte f2bh spbrg3 eusart3 baud rate generator f2ah rcreg3 eusart3 receive data fifo f29h txreg3 eusart3 transmit data fifo f28h dsconl ? ? ? ? ? ulpwdis dsbor release f27h dsconh dsen ? ? ? ? ? ?rtcwdis f26h dswakel dsflt bor dsulp dswdt dsrtc dsmclr dsicd dspor f25h dswakeh ? ? ? ? ? ? ?dsint0 f24h dsgpr0 deep sleep general purpose register 0 f23h dsgpr1 deep sleep general purpose register 1 f22h dsgpr2 deep sleep general purpose register 2 f21h dsgpr3 deep sleep general purpose register 3 f20h spbrgh2 eusart2 baud rate generator high byte f1fh spbrg2 eusart2 baud rate generator f1eh rcreg2 receive data fifo f1dh txreg2 transmit data fifo f1ch pstr2con cmpl1 cmpl0 ? strsync strd strc strb stra f1bh pstr3con cmpl1 cmpl0 ? strsync strd strc strb stra f1ah ssp2stat smp cke d/a psr/w ua bf f19h ssp2con1 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 f18h ssp2con2 gcen ackstat ackdt acken rcen pen rsen sen f17h ssp2msk msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 f16h tmr5h timer5 register high byte f15h tmr5l timer5 register low byte f14h t5con tmr5cs1 tmr5cs0 t5ckps1 t5ckps0 soscen t5sync rd16 tmr5on f13h t5gcon tmr5ge t5gpol t5gtm t5gspm t5ggo/t5 don e t5gval t5gss1 t5gss0 f12h ccpr4h capture/compare/pwm register 4 high byte f11h ccpr4l capture/compare/pwm register 4 low byte f10h ccp4con ? ? dc4b1 dc4b0 ccp4m3 ccp4m2 ccp4m1 ccp4m0 f0fh ccpr5h capture/compare/pwm register 5 high byte f0eh ccpr5l capture/compare/pwm register 5 low byte f0dh ccp5con ? ? dc5b1 dc5b0 ccp5m3 ccp5m2 ccp5m1 ccp5m0 f0ch ccpr6h capture/compare/pwm register 6 high byte f0bh ccpr6l capture/compare/pwm register 6 low byte f0ah ccp6con ? ? dc6b1 dc6b0 ccp6m3 ccp6m2 ccp6m1 ccp6m0 f09h ccpr7h capture/compare/pwm register 7 high byte f08h ccpr7l capture/compare/pwm register 7 low byte f07h ccp7con ? ? dc7b1 dc7b0 ccp7m3 ccp7m2 ccp7m1 ccp7m0 f06h tmr4 timer4 register f05h pr4 timer4 period register f04h t4con ? t4outps3 t4outps2 t4outps1 t4outps0 tmr4on t4ckps1 t4ckps0 table 6-2: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 legend: ? = unimplemented, read as ? 0 ?.
? 2012 microchip technology inc. ds30575a-page 129 pic18f97j94 family f03h ssp2buf mssp2 receive buffer/transmit register f02h ssp2add mssp2 address register in i 2 c? slave mode. mssp1 baud rate reload register in i 2 c master mode. f01h ancfg ? ? ? ? ? vbg6en vbg2en vbgen f00h dmacon2 dlycyc3 dlycyc2 dlycyc1 dlycyc0 intlvl3 intlvl2 intlvl1 intlvl0 effh rcsta4 spen rx9 sren cren adden ferr oerr rx9d efeh txsta4 csrc tx9 txen sync sendb brgh trmt tx9d efdh baudcon4 abdovf rcidl rxdtp txckp brg16 iren wue abden efch spbrgh4 eusart4 baud rate generator high byte efbh spbrg4 eusart4 baud rate generator efah rcreg4 eusart4 receive data fifo ef9h txreg4 eusart4 transmit data fifo ef8h ctmucon1 ctmuen ? ctmusidl tgen edgen edgseqen idissen trigen ef7h ctmucon2 itrim5 itrim4 itrim3 itrim2 itrim1 itrim0 irng1 irng0 ef6h ctmucon3 edg2en edg2pol edg2sel3 edg2sel2 edg2sel1 edg2sel0 ? ? ef5h ctmucon4 edg1en edg1pol edg1sel3 edg1sel2 edg1sel1 edg1sel0 edg2stat edg1stat ef4h pmd0 ccp10md ccp9md ccp8md ccp7md ccp6md ccp5md ccp4md eccp3md ef3h pmd1 eccp2md eccp1md uart4md uart3md uart2md uart1md ssp2md ssp1md ef2h pmd2 tmr8md tmr6md tmr5md tmr4md tmr3md tmr2md tmr1md tmr0md ef1h pmd3 txmmd ctmumd adcmd rtccmd lcdmd pspmd refo1md refo2md ef0h pmd4 cmp1md cmp2md cmp3md usbmd iocmd lvdmd ?embmd eefh mdcon mden mdoe mdslr mdopol mdo ? ?mdbit eeeh mdsrc mdsodis ? ? ? mdsrc3 mdsrc2 mdsrc1 mdsrc0 eedh mdcarh mdchodis mdchpol mdchsync ? mdch3 mdch2 mdch1 mdch0 eech mdcarl mdclodis mdclpol mdclsync ? mdcl3 mdcl2 mdcl1 mdcl0 eebh odcon1 eccp2od eccp1od usart4od usart3od usart2od usart1od ssp2od ssp1od eeah odcon2 ccp10od ccp9od ccp8od ccp7od ccp6od ccp5od ccp4od eccp3od ee9h trisk trisk7 trisk6 trisk5 trisk4 trisk3 trisk2 trisk1 trisk0 ee8h latk latk7 latk6 latk5 latk4 latk3 latk2 latk1 latk0 ee7h portk rk7 rk6 rk5 rk4 rk3 rk2 rk1 rk0 ee6h trisl trisl7 trisl6 trisl5 trisl4 trisl3 trisl2 trisl1 trisl0 ee5h latl latl7 latl6 latl5 latl4 latl3 latl2 latl1 latl0 ee4h portl rl7 rl6 rl5 rl4 rl3 rl2 rl1 rl0 ee3h memcon ebdis ?wait1wait0 ? ?wm1wm0 ee2h refo1con on ?sidl oe rslp ? divswen active ee1h refo1con1 ? ? ? ? rosel3 rosel2 rosel1 rosel0 ee0h refo1con2 rodiv7 rodiv6 rodiv5 rodiv4 rodiv3 rodi v2 rodiv1 rodiv0 edfh refo1con3 ? rodiv14 rodiv13 rodiv12 rodiv11 rodiv10 rodiv9 rodiv8 edeh refo2con on ?sidl oe rslp ? divswen active eddh refo2con1 ? ? ? ? rosel3 rosel2 rosel1 rosel0 edch refo2con2 rodiv7 rodiv6 rodiv5 rodiv4 rodiv3 rodiv2 rodiv1 rodiv0 edbh refo2con3 ? rodiv14 rodiv13 rodiv12 rodiv11 rodiv10 rodiv9 rodiv8 edah lcdps wft biasmd lcda wa lp3 lp2 lp1 lp0 ed9h lcdcon lcden slpen werr cs1 cs0 lmux2 lmux1 lmux0 ed8h lcdreg cpen ? bias2 bias1 bias0 mode13 clksel1 clksel0 ed7h lcdref lcdire ? lcdcst2 lcdcst1 lcdcst0 vlcd3pe vlcd2pe vlcd1pe ed6h lcdrl lrlap1 lr lap0 lrlbp1 lrlbp0 ? lrlat2 lrlat1 lrlat0 ed5h lcdse7 se63 se62 se61 se60 se59 se58 se57 se56 ed4h lcdse6 se55 se54 se53 se52 se51 se50 se49 se48 ed3h lcdse5 se47 se46 se45 se44 se43 se42 se41 se40 ed2h lcdse4 se39 se38 s37 se36 se35 se34 se33 se32 ed1h lcdse3 se31 se30 se29 se28 se27 se26 se25 se24 ed0h lcdse2 se23 se22 se21 se20 se19 se18 se17 se16 table 6-2: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 legend: ? = unimplemented, read as ? 0 ?.
pic18f97j94 family ds30575a-page 130 ? 2012 microchip technology inc. ecfh lcdse1 se15 se14 se13 se12 se11 se10 se09 se08 eceh lcdse0 se07 se06 se05 se04 se03 se02 se01 se00 ecdh lcddata63 s63c7 s62c7 s61c7 s60c7 s59c7 s58c7 s57c7 s56c7 ecch lcddata62 s55c7 s54c7 s53c7 s52c7 s51c7 s50c7 s49c7 s48c7 ecbh lcddata61 s47c7 s46c7 s45c7 s44c7 s43c7 s42c7 s41c7 s40c7 ecah lcddata60 s39c7 s38c7 s37c7 s36c7 s35c7 s34c7 s33c7 s32c7 ec9h lcddata59 s31c7 s30c7 s29c7 s28c7 s27c7 s26c7 s25c7 s24c7 ec8h lcddata58 s23c7 s22c7 s21c7 s20c7 s19c7 s18c7 s17c7 s16c7 ec7h lcddata57 s15c7 s14c7 s13c7 s12c7 s11c7 s10c7 s09c7 s08c7 ec6h lcddata56 s07c7 s06c7 s05c7 s04c7 s03c7 s02c7 s01c7 s00c7 ec5h lcddata55 s63c6 s62c6 s61c6 s60c6 s59c6 s58c6 s57c6 s56c6 ec4h lcddata54 s55c6 s54c6 s53c6 s52c6 s51c6 s50c6 s49c6 s48c6 ec3h lcddata53 s47c6 s46c6 s45c6 s44c6 s43c6 s42c6 s41c6 s40c6 ec2h lcddata52 s39c6 s38c6 s37c6 s36c6 s35c6 s34c6 s33c6 s32c6 ec1h lcddata51 s31c6 s30c6 s29c6 s28c6 s27c6 s26c6 s25c6 s24c6 ec0h lcddata50 s23c6 s22c6 s21c6 s20c6 s19c6 s18c6 s17c6 s16c6 ebfh lcddata49 s15c6 s14c6 s13c6 s12c6 s11c6 s10c6 s09c6 s08c6 ebeh lcddata48 s07c6 s06c6 s05c6 s04c6 s03c6 s02c6 s01c6 s00c6 ebdh lcddata47 s63c5 s62c5 s61c5 s60c5 s59c5 s58c5 s57c5 s56c5 ebch lcddata46 s55c5 s54c5 s53c5 s52c5 s51c5 s50c5 s49c5 s48c5 ebbh lcddata45 s47c5 s46c5 s45c5 s44c5 s43c5 s42c5 s41c5 s40c5 ebah lcddata44 s39c5 s38c5 s37c5 s36c5 s35c5 s34c5 s33c5 s32c5 eb9h lcddata43 s31c5 s30c5 s29c5 s28c5 s27c5 s26c5 s25c5 s24c5 eb8h lcddata42 s23c5 s22c5 s21c5 s20c5 s19c5 s18c5 s17c5 s16c5 eb7h lcddata41 s15c5 s14c5 s13c5 s12c5 s11c5 s10c5 s09c5 s08c5 eb6h lcddata40 s07c5 s06c5 s05c5 s04c5 s03c5 s02c5 s01c5 s00c5 eb5h lcddata39 s63c4 s62c4 s61c4 s60c4 s59c4 s58c4 s57c4 s56c4 eb4h lcddata38 s55c4 s54c4 s53c4 s52c4 s51c4 s50c4 s49c4 s48c4 eb3h lcddata37 s47c4 s46c4 s45c4 s44c4 s43c4 s42c4 s41c4 s40c4 eb2h lcddata36 s39c4 s38c4 s37c4 s36c4 s35c4 s34c4 s33c4 s32c4 eb1h lcddata35 s31c4 s30c4 s29c4 s28c4 s27c4 s26c4 s25c4 s24c4 eb0h lcddata34 s23c4 s22c4 s21c4 s20c4 s19c4 s18c4 s17c4 s16c4 eafh lcddata33 s15c4 s14c4 s13c4 s12c4 s11c4 s10c4 s09c4 s08c4 eaeh lcddata32 s07c4 s06c4 s05c4 s04c4 s03c4 s02c4 s01c4 s00c4 eadh lcddata31 s63c3 s62c3 s61c3 s60c3 s59c3 s58c3 s57c3 s56c3 each lcddata30 s55c3 s54c3 s53c3 s52c3 s51c3 s50c3 s49c3 s48c3 eabh lcddata29 s47c3 s46c3 s45c3 s44c3 s43c3 s42c3 s41c3 s40c3 eaah lcddata28 s39c3 s38c3 s37c3 s36c3 s35c3 s34c3 s33c3 s32c3 ea9h lcddata27 s31c3 s30c3 s29c3 s28c3 s27c3 s26c3 s25c3 s24c3 ea8h lcddata26 s23c3 s22c3 s21c3 s20c3 s19c3 s18c3 s17c3 s16c3 ea7h lcddata25 s15c3 s14c3 s13c3 s12c3 s11c3 s10c3 s09c3 s08c3 ea6h lcddata24 s07c3 s06c3 s05c3 s04c3 s03c3 s02c3 s01c3 s00c3 ea5h lcddata23 s63c2 s62c2 s61c2 s60c2 s59c2 s58c2 s57c2 s56c2 ea4h lcddata22 s55c2 s54c2 s53c2 s52c2 s51c2 s50c2 s49c2 s48c2 ea3h lcddata21 s47c2 s46c2 s45c2 s44c2 s43c2 s42c2 s41c2 s40c2 ea2h lcddata20 s39c2 s38c2 s37c2 s36c2 s35c2 s34c2 s33c2 s32c2 ea1h lcddata19 s31c2 s30c2 s29c2 s28c2 s27c2 s26c2 s25c2 s24c2 ea0h lcddata18 s23c2 s22c2 s21c2 s20c2 s19c2 s18c2 s17c2 s16c2 e9fh lcddata17 s15c2 s14c2 s13c2 s12c2 s11c2 s10c2 s09c2 s08c2 e9eh lcddata16 s07c2 s06c2 s05c2 s04c2 s03c2 s02c2 s01c2 s00c2 e9dh lcddata15 s63c1 s62c1 s61c1 s60c1 s59c1 s58c1 s57c1 s56c1 table 6-2: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 legend: ? = unimplemented, read as ? 0 ?.
? 2012 microchip technology inc. ds30575a-page 131 pic18f97j94 family e9ch lcddata14 s55c1 s54c1 s53c1 s52c1 s51c1 s50c1 s49c1 s48c1 e9bh lcddata13 s47c1 s46c1 s45c1 s44c1 s43c1 s42c1 s41c1 s40c1 e9ah lcddata12 s39c1 s38c1 s37c1 s36c1 s35c1 s34c1 s33c1 s32c1 e99h lcddata11 s31c1 s30c1 s29c1 s28c1 s27c1 s26c1 s25c1 s24c1 e98h lcddata10 s23c1 s22c1 s21c1 s20c1 s19c1 s18c1 s17c1 s16c1 e97h lcddata9 s15c1 s14c1 s13c1 s12c1 s11c1 s10c1 s09c1 s08c1 e96h lcddata8 s07c1 s06c1 s05c1 s04c1 s03c1 s02c1 s01c1 s00c1 e95h lcddata7 s63c0 s62c0 s61c0 s60c0 s59c0 s58c0 s57c0 s56c0 e94h lcddata6 s55c0 s54c0 s53c0 s52c0 s51c0 s50c0 s49c0 s48c0 e93h lcddata5 s47c0 s46c0 s45c0 s44c0 s43c0 s42c0 s41c0 s40c0 e92h lcddata4 s39c0 s38c0 s37c0 s36c0 s35c0 s34c0 s33c0 s32c0 e91h lcddata3 s31c0 s30c0 s29c0 s28c0 s27c0 s26c0 s25c0 s24c0 e90h lcddata2 s23c0 s22c0 s21c0 s20c0 s19c0 s18c0 s17c0 s16c0 e8fh lcddata1 s15c0 s14c0 s13c0 s12c0 s11c0 s10c0 s09c0 s08c0 e8eh lcddata0 s07c0 s06c0 s05c0 s04c0 s03c0 s02c0 s01c0 s00c0 e8dh adcon2h pvcfg1 pvcfg0 nvcfg0 offcal bufregen cscna ? ? e8ch adcon2l bufs smpi4 smpi3 smpi2 smpi1 smpi0 bufm alts e8bh adcon3h adrc extsam pumpen samc4 samc3 samc2 samc1 samc0 e8ah adcon3l adcs7 adcs6 adcs5 adcs4 adcs3 adcs2 adcs1 adcs0 e89h adcon5h asena lpena ctmureq ? ? ? asintmd1 asintmd0 e88h adcon5l ? ? ? ?wm1wm0cm1cm0 e87h adchs0h ch0nb2 ch0nb1 ch0 nb0 ch0sb4 ch0sb3 ch0sb2 ch0sb1 ch0sb0 e86h adchs0l ch0na2 ch0na1 ch0 na0 ch0sa4 ch0sa3 ch0sa2 ch0sa1 ch0sa0 e85h adcss1h ? css30 css29 css28 css27 css26 css25 css24 e84h adcss1l css23 css22 css21 css20 css19 css18 css17 css16 e83h adcss0h css15 css14 css13 css12 css11 css10 css9 css8 e82h adcss0l css7 css6 css5 css4 css3 css2 css1 css0 e81h adchit1h ? chh30 chh29 chh28 chh27 chh26 chh25 chh24 e80h adchit1l chh23 chh22 chh21 chh20 chh19 chh18 chh17 chh16 e7fh adchit0h chh15 chh14 chh13 chh12 chh11 chh10 chh9 chh8 e7eh adchit0l chh7 chh6 chh5 chh4 chh3 chh2 chh1 chh0 e7dh adctmuen1h ? ctmuen30 ctmuen29 ctmuen28 ctmue n27 ctmuen26 ctmuen25 ctmuen24 e7ch adctmuen1l ctmuen23 ctmuen22 ctmuen21 ctmuen20 ctmuen19 ctmuen18 ctmuen17 ctmuen16 e7bh adctmuen0h ctmuen15 ctmuen14 ctmuen13 ctmuen12 ctmuen11 ctmuen10 ctmuen9 ctmuen8 e7ah adctmuen0l ctmuen7 ctmuen6 ctmuen5 ctmuen4 ctmuen3 ctmuen2 ctmuen1 ctmuen0 e79h adcbuf25h a/d result register 25 high byte e78h adcbuf25l a/d result register 25 low byte e77h adcbuf24h a/d result register 24 high byte e76h adcbuf24l a/d result register 24 low byte e75h adcbuf23h a/d result register 23 high byte e74h adcbuf23l a/d result register 23 low byte e73h adcbuf22h a/d result register 22 high byte e72h adcbuf22l a/d result register 22 low byte e71h adcbuf21h a/d result register 21 high byte e70h adcbuf21l a/d result register 21 low byte e6fh adcbuf20h a/d result register 20 high byte e6eh adcbuf20l a/d result register 20 low byte e6dh adcbuf19h a/d result register 19 high byte e6ch adcbuf19l a/d result register 19 low byte e6bh adcbuf18h a/d result register 18 high byte e6ah adcbuf18l a/d result register 18 low byte table 6-2: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 legend: ? = unimplemented, read as ? 0 ?.
pic18f97j94 family ds30575a-page 132 ? 2012 microchip technology inc. e69h adcbuf17h a/d result register 17 high byte e68h adcbuf17l a/d result register 17 low byte e67h adcbuf16h a/d result register 16 high byte e66h adcbuf16l a/d result register 16 low byte e65h adcbuf15h a/d result register 15 high byte e64h adcbuf15l a/d result register 15 low byte e63h adcbuf14h a/d result register 14 high byte e62h adcbuf14l a/d result register 14 low byte e61h adcbuf13h a/d result register 13 high byte e60h adcbuf13l a/d result register 13 low byte e5fh adcbuf12h a/d result register 12 high byte e5eh adcbuf12l a/d result register 12 low byte e5dh adcbuf11h a/d result register 11 high byte e5ch adcbuf11l a/d result register 11 low byte e5bh adcbuf10h a/d result register 10 high byte e5ah adcbuf10l a/d result register 10 low byte e59h adcbuf9h a/d result register 9 high byte e58h adcbuf9l a/d result register 9 low byte e57h adcbuf8h a/d result register 8 high byte e56h adcbuf8l a/d result register 8 low byte e55h adcbuf7h a/d result register 7 high byte e54h adcbuf7l a/d result register 7 low byte e53h adcbuf6h a/d result register 6 high byte e52h adcbuf6l a/d result register 6 low byte e51h adcbuf5h a/d result register 5 high byte e50h adcbuf5l a/d result register 5 low byte e4fh adcbuf4h a/d result register 4 high byte e4eh adcbuf4l a/d result register 4 low byte e4dh adcbuf3h a/d result register 3 high byte e4ch adcbuf3l a/d result register 3 low byte e4bh adcbuf2h a/d result register 2 high byte e4ah adcbuf2l a/d result register 2 low byte e49h adcbuf1h a/d result register 1 high byte e48h adcbuf1l a/d result register 1 low byte e47h ancon1 ansel7 ansel6 ansel5 ansel4 ansel3 ansel2 ansel1 ansel0 e46h ancon2 ansel15 ansel14 ansel13 ansel12 ansel11 ansel10 ansel9 ansel8 e45h ancon3 ansel23 ansel22 ansel21 ansel20 ansel19 ansel18 ansel17 ansel16 e44h rpinr52_53 pbio7r<3:0> pbio6r<3:0> e43h rpinr50_51 pbio5r<3:0> pbio4r<3:0> e42h rpinr48_49 pbio3r<3:0> pbio2r<3:0> e41h rpinr46_47 pbio1r<3:0> pbio0r<3:0> e40h rpinr44_45 t5ckir<3:0> t5gr<3:0> e3fh rpinr42_43 t3ckir<3:0> t3gr<3:0> e3eh rpinr40_41 t1ckir<3:0> t1gr<3:0> e3dh rpinr38_39 t0ckir<3:0> ccp10r<3:0> e3ch rpinr36_37 ccp9r<3:0> ccp8r<3:0> e3bh rpinr34_35 ccp7r<3:0> ccp6r<3:0> e3ah rpinr32_33 ccp5r<3:0> ccp4r<3:0> e39h rpinr30_31 mdcin2r<3:0> mdcin1r<3:0> e38h rpinr28_29 mdminr<3:0> int3r<3:0> e37h rpinr26_27 int2r<3:0> int1r<3:0> table 6-2: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 legend: ? = unimplemented, read as ? 0 ?.
? 2012 microchip technology inc. ds30575a-page 133 pic18f97j94 family e36h rpinr24_25 ioc7r<3:0> ioc6r<3:0> e35h rpinr22_23 ioc5r<3:0> ioc4r<3:0> e34h rpinr20_21 ioc3r<3:0> ioc2r<3:0> e33h rpinr18_19 ioc1r<3:0> ioc0r<3:0> e32h rpinr16_17 eccp3r<3:0> eccp2r<3:0> e31h rpinr14_15 eccp1r<3:0> flt0r<3:0> e30h rpinr12_13 ss2r<3:0> sdi2r<3:0> e2fh rpinr10_11 sck2r<3:0> ss1r<3:0> e2eh rpinr8_9 sdi1r<3:0> sck1r<3:0> e2dh rpinr6_7 u4txr<3:0> u4rxr<3:0> e2ch rpinr4_5 u3txr<3:0> u3rxr<3:0> e2bh rpinr2_3 u2txr<3:0> u2rxr<3:0> e2ah rpinr0_1 u1txr<3:0> u1rxr<3:0> e29h rpor46 ? ? ? ? rpo46r<3:0> e28h rpor44_45 rpo45r<3:0> rpo44r<3:0> e27h rpor42_43 rpo43r<3:0> rpo42r<3:0> e26h rpor40_41 rpo41r<3:0> rpo40r<3:0> e25h rpor38_39 rpo39r<3:0> rpo38r<3:0> e24h rpor36_37 rpo37r<3:0> rpo36r<3:0> e23h rpor34_35 rpo35r<3:0> rpo34r<3:0> e22h rpor32_33 rpo33r<3:0> rpo32r<3:0> e21h rpor30_31 rpo31r<3:0> rpo30r<3:0> e20h rpor28_29 rpo29r<3:0> rpo28r<3:0> e1fh rpor26_27 rpo27r<3:0> rpo26r<3:0> e1eh rpor24_25 rpo25r<3:0> rpo24r<3:0> e1dh rpor22_23 rpp23r<3:0> rpo22r<3:0> e1ch rpor20_21 rpo21r<3:0> rpo20r<3:0> e1bh rpor18_19 rpo19r<3:0> rpo18r<3:0> e1ah rpor16_17 rpo17r<3:0> rpo16r<3:0> e19h rpor14_15 rpo15r<3:0> rpo14r<3:0> e18h rpor12_13 rpo13r<3:0> rpo12r<3:0> e17h rpor10_11 rpo11r<3:0> rpo10r<3:0> e16h rpor8_9 rpo9r<3:0> rpo8r<3:0> e15h rpor6_7 rpo7r<3:0> rpo6r<3:0> e14h rpor4_5 rpo5r<3:0> rpo4r<3:0> e13h rpor2_3 rpo3r<3:0> rpo2r<3:0> e12h rpor0_1 rpo1r<3:0> rpo0r<3:0> e11h ucfg uteye uoemon ? upuen utrdis fsen ppb1 ppb0 e10h uie ? sofie stallie idleie trnie actvie uerrie urstie e0fh ueie btsee ? ? btoee dfn8ee crc16ee crc5ee pidee e0eh uep15 ? ? ? ephshk epcondis epouten epinen epstall e0dh uep14 ? ? ? ephshk epcondis epouten epinen epstall e0ch uep13 ? ? ? ephshk epcondis epouten epinen epstall e0bh uep12 ? ? ? ephshk epcondis epouten epinen epstall e0ah uep11 ? ? ? ephshk epcondis epouten epinen epstall e09h uep10 ? ? ? ephshk epcondis epouten epinen epstall e08h uep9 ? ? ? ephshk epcondis epouten epinen epstall e07h uep8 ? ? ? ephshk epcondis epouten epinen epstall e06h uep7 ? ? ? ephshk epcondis epouten epinen epstall e05h uep6 ? ? ? ephshk epcondis epouten epinen epstall e04h uep5 ? ? ? ephshk epcondis epouten epinen epstall table 6-2: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 legend: ? = unimplemented, read as ? 0 ?.
pic18f97j94 family ds30575a-page 134 ? 2012 microchip technology inc. e03h uep4 ? ? ? ephshk epcondis epouten epinen epstall e02h uep3 ? ? ? ephshk epcondis epouten epinen epstall e01h uep2 ? ? ? ephshk epcondis epouten epinen epstall e00h uep1 ? ? ? ephshk epcondis epouten epinen epstall dffh uep0 ? ? ? ephshk epcondis epouten epinen epstall dfeh unimplemented ? ? ? ? ? ? ? ? dfdh unimplemented ? ? ? ? ? ? ? ? dfch unimplemented ? ? ? ? ? ? ? ? dfbh unimplemented ? ? ? ? ? ? ? ? dfah unimplemented ? ? ? ? ? ? ? ? table 6-2: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 legend: ? = unimplemented, read as ? 0 ?.
? 2012 microchip technology inc. ds30575a-page 135 pic18f97j94 family 6.3.5 status register the status register, shown in register 6-2 , contains the arithmetic status of the alu. the status register can be the operand for any instruction, as with any other register. if the status register is the destination for an instruction that affects the z, dc, c, ov or n bits, the write to these five bits is disabled. these bits are set or cleared according to the device logic. therefore, the result of an instruction with the status register as destination may be different than intended. for example, clrf status will set the z bit but leave the other bits unchanged. the status register then reads back as ? 000u u1uu ?. it is recommended, therefore, that only bcf, bsf, swapf, movff and movwf instructions be used to alter the status register because these instructions do not affect the z, c, dc, ov or n bits in the status register. for other instructions not affecting any status bits, see the instruction set summaries in table 29-2 and table 29-3 . note: the c and dc bits operate, in subtraction, as borrow and digit borrow bits, respectively. register 6-2: status register u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ?novzdc ( 1 ) c ( 2 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 n: negative bit this bit is used for signed arithmetic (2?s complement). it indicates whether the result was negative (alu msb = 1 ). 1 = result was negative 0 = result was positive bit 3 ov: overflow bit this bit is used for signed arithmetic (2?s complement). it indicates an overflow of the seven-bit magnitude which causes the sign bit (bit 7) to change state. 1 = overflow occurred for signed arithmetic (in this arithmetic operation) 0 = no overflow occurred bit 2 z: zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc: digit carry/borrow bit ( 1 ) for addwf, addlw, sublw and subwf instructions: 1 = a carry-out from the 4th low-order bit of the result occurred 0 = no carry-out from the 4th low-order bit of the result bit 0 c: carry/borrow bit ( 2 ) for addwf, addlw, sublw and subwf instructions: 1 = a carry-out from the most significant bit of the result occurred 0 = no carry-out from the most significant bit of the result occurred note 1: for borrow, the polarity is reversed. a subtraction is ex ecuted by adding the 2?s complement of the second operand. for rotate ( rrf, rlf ) instructions, this bit is loaded with eit her bit 4 or bit 3 of the source register. 2: for borrow, the polarity is reversed. a subtraction is executed by adding the 2?s complement of the second operand. for rotate ( rrf, rlf ) instructions, this bit is loaded with either the high or low-order bit of the source register.
pic18f97j94 family ds30575a-page 136 ? 2012 microchip technology inc. 6.4 data addressing modes while the program memory can be addressed in only one way, through the program counter, information in the data memory space can be addressed in several ways. for most instructions, the addressing mode is fixed. other instructions may use up to three modes, depending on which operands are used and whether or not the extended instruction set is enabled. the addressing modes are: ? inherent ? literal ?direct ?indirect an additional addressing mode, indexed literal offset, is available when the extended instruction set is enabled (xinst configuration bit = 1 ). for details on this mode?s operation, see section 6.6.1 ?indexed addressing with literal offset? . 6.4.1 inherent and literal addressing many pic18 control instructions do not need any argument at all. they either perform an operation that globally affects the device or they operate implicitly on one register. this addressing mode is known as inherent addressing. examples of this mode include sleep , reset and daw . other instructions work in a similar way, but require an additional explicit argument in the opcode. this method is known as the literal addressing mode because the instructions require some literal value as an argument. examples of this include addlw and movlw which, respectively, add or move a literal value to the w register. other examples include call and goto , which include a 20-bit program memory address. 6.4.2 direct addressing direct addressing specifies all or part of the source and/or destination address of the operation within the opcode itself. the options are specified by the arguments accompanying the instruction. in the core pic18 instruction set, bit-oriented and byte-oriented instructions use some version of direct addressing by default. all of these instructions include some 8-bit literal address as their least significant byte. this address specifies the instruction?s data source as either a register address in one of the banks of data ram (see section 6.3.3 ?general purpose register file? ) or a location in the access bank (see section 6.3.2 ?access bank? ). the access ram bit, ?a?, determines how the address is interpreted. when ?a? is ? 1 ?, the contents of the bsr ( section 6.3.1 ?bank select register? ) are used with the address to determine the complete 12-bit address of the register. when ?a? is ? 0 ?, the address is interpreted as being a register in the access bank. addressing that uses the access ram is sometimes also known as direct forced addressing mode. a few instructions, such as movff , include the entire 12-bit address (either source or destination) in their opcodes. in these cases, the bsr is ignored entirely. the destination of the operation?s results is determined by the destination bit, ?d?. when ?d? is ? 1 ?, the results are stored back in the source register, overwriting its origi- nal contents. when ?d? is ? 0 ?, the results are stored in the w register. instructions without the ?d? argument have a destination that is implicit in the instruction, either the target register being operated on or the w register. 6.4.3 indirect addressing indirect addressing allows the user to access a location in data memory without giving a fixed address in the instruction. this is done by using file select registers (fsrs) as pointers to the locations to be read or written to. since the fsrs are themselves located in ram as special function registers, they can also be directly manipulated under program control. this makes fsrs very useful in implementing data structures such as tables and arrays in data memory. the registers for indirect addressing are also implemented with indirect file operands (indfs) that permit automatic manipulation of the pointer value with auto-incrementing, auto-decrementing or offsetting with another value. this allows for efficient code using loops, such as the example of clearing an entire ram bank in example 6-5 . it also enables users to perform indexed addressing and other stack pointer operations for program memory in data memory. example 6-5: how to clear ram (bank 1) using indirect addressing note: the execution of some instructions in the core pic18 instruction set are changed when the pic18 extended instruction set is enabled. for more information, see section 6.6 ?data memory and the extended instruction set? . lfsr fsr0, 100h ; next clrf postinc0 ; clear indf ; register then ; inc pointer btfss fsr0h, 1 ; all done with ; bank1? bra next ; no, clear next continue ; yes, continue
? 2012 microchip technology inc. ds30575a-page 137 pic18f97j94 family 6.4.3.1 fsr registers and the indf operand at the core of indirect addressing are three sets of registers: fsr0, fsr1 and fsr2. each represents a pair of 8-bit registers: fsrnh and fsrnl. the four upper bits of the fsrnh register are not used, so each fsr pair holds a 12-bit value. this represents a value that can address the entire range of the data memory in a linear fashion. the fsr register pairs, then, serve as pointers to data memory locations. indirect addressing is accomplished with a set of indi- rect file operands, indf0 through indf2. these can be thought of as ?virtual? registers. the operands are mapped in the sfr space, but are not physically imple- mented. reading or writing to a particular indf register actually accesses its corresponding fsr register pair. a read from indf1, for example, reads the data at the address indicated by fsr1h:fsr1l. instructions that use the indf registers as operands actually use the contents of their corresponding fsr as a pointer to the instruction?s target. the indf operand is just a convenient way of using the pointer. because indirect addressing uses a full 12-bit address, data ram banking is not necessary. thus, the current contents of the bsr and the access ram bit have no effect on determining the target address. figure 6-8: indirect addressing fsr1h:fsr1l 0 7 data memory 000h 100h 200h 300h f00h e00h fffh bank 0 bank 1 bank 2 bank 14 bank 15 bank 3 through bank 13 addwf, indf1, 1 0 7 using an instruction with one of the indirect addressing registers as the operand.... ...uses the 12-bit address stored in the fsr pair associated with that register.... ...to determine the data memory location to be used in that operation. in this case, the fsr1 pair contains fcch. this means the contents of location fcch will be added to that of the w register and stored back in fcch. xxxx 1111 11001100
pic18f97j94 family ds30575a-page 138 ? 2012 microchip technology inc. 6.4.3.2 fsr registers and postinc, postdec, preinc and plusw in addition to the indf operand, each fsr register pair also has four additional indirect operands. like indf, these are ?virtual? registers that cannot be indirectly read or written to. accessing these registers actually accesses the associated fsr register pair, but also performs a specific action on its stored value. these operands are: ? postdec ? accesses the fsr value, then automatically decrements it by ? 1 ? afterwards ? postinc ? accesses the fsr value, then automatically increments it by ? 1 ? afterwards ? preinc ? increments the fsr value by ? 1 ?, then uses it in the operation ? plusw ? adds the signed value of the w register (range of -127 to 128) to that of the fsr and uses the new value in the operation in this context, accessing an indf register uses the value in the fsr registers without changing them. similarly, accessing a plusw register gives the fsr value, offset by the value in the w register, with neither value actually changed in the operation. accessing the other virtual registers changes the value of the fsr registers. operations on the fsrs with postdec, postinc and preinc affect the entire register pair. rollovers of the fsrnl register, from ffh to 00h, carry over to the fsrnh register. on the other hand, results of these operations do not change the value of any flags in the status register (for example, z, n and ov bits). the plusw register can be used to implement a form of indexed addressing in the data memory space. by manipulating the value in the w register, users can reach addresses that are fixed offsets from pointer addresses. in some applications, this can be used to implement some powerful program control structure, such as software stacks, inside of data memory. 6.4.3.3 operations by fsrs on fsrs indirect addressing operations that target other fsrs or virtual registers represent special cases. for example, using an fsr to point to one of the virtual registers will not result in successful operations. as a specific case, assume that the fsr0h:fsr0l registers contain fe7h, the address of indf1. attempts to read the value of the indf1, using indf0 as an operand, will return 00h. attempts to write to indf1, using indf0 as the operand, will result in a nop . on the other hand, using the virtual registers to write to an fsr pair may not occur as planned. in these cases, the value will be written to the fsr pair, but without any incrementing or decrementing. thus, writing to indf2 or postdec2 will write the same value to the fsr2h:fsr2l. since the fsrs are physical registers mapped in the sfr space, they can be manipulated through all direct operations. users should proceed cautiously when working on these registers, however, particularly if their code uses indirect addressing. similarly, operations by indirect addressing are gener- ally permitted on all other sfrs. users should exercise the appropriate caution, so that they do not inadvertently change settings that might affect the operation of the device. 6.5 program memory and the extended instruction set the operation of program memory is unaffected by the use of the extended instruction set. enabling the extended instruction set adds five additional two-word commands to the existing pic18 instruction set: addfsr , callw , movsf , movss and subfsr . these instructions are executed as described in section 6.2.4 ?two-word instructions? .
? 2012 microchip technology inc. ds30575a-page 139 pic18f97j94 family 6.6 data memory and the extended instruction set enabling the pic18 extended instruction set (xinst configuration bit = 1 ) significantly changes certain aspects of data memory and its addressing. using the access bank for many of the core pic18 instructions introduces a new addressing mode for the data memory space. this mode also alters the behavior of indirect addressing using fsr2 and its associated operands. what does not change is just as important. the size of the data memory space is unchanged, as well as its linear addressing. the sfr map remains the same. core pic18 instructions can still operate in both direct and indirect addressing mode. inherent and literal instructions do not change at all. indirect addressing with fsr0 and fsr1 also remains unchanged. 6.6.1 indexed addressing with literal offset enabling the pic18 extended instruction set changes the behavior of indirect addressing using the fsr2 register pair and its associated file operands. under the proper conditions, instructions that use the access bank ? that is, most bit-oriented and byte-oriented instructions ? can invoke a form of indexed addressing using an offset specified in the instruction. this special addressing mode is known as indexed addressing with literal offset or the indexed literal offset mode. when using the extended instruction set, this addressing mode requires the following: ? use of the access bank (?a? = 0 ) ? a file address argument that is less than or equal to 5fh under these conditions, the file address of the instruction is not interpreted as the lower byte of an address (used with the bsr in direct addressing) or as an 8-bit address in the access bank. instead, the value is interpreted as an offset value to an address pointer specified by fsr2. the offset and the contents of fsr2 are added to obtain the target address of the operation. 6.6.2 instructions affected by indexed literal offset mode any of the core pic18 instructions that can use direct addressing are potentially affected by the indexed literal offset addressing mode. this includes all byte-oriented and bit-oriented instructions, or almost one-half of the standard pic18 instruction set. instruc- tions that only use inherent or literal addressing modes are unaffected. additionally, byte-oriented and bit-oriented instructions are not affected if they do not use the access bank (access ram bit = 1 ), or include a file address of 60h or above. instructions meeting these criteria will continue to execute as before. a comparison of the different possible addressing modes when the extended instruction set is enabled is shown in figure 6-9 . those who desire to use byte-oriented or bit-oriented instructions in the indexed literal offset mode should note the changes to assembler syntax for this mode. this is described in more detail in section 29.2.1 ?extended instruction syntax? .
pic18f97j94 family ds30575a-page 140 ? 2012 microchip technology inc. figure 6-9: comparing addressing options for bit-oriented and byte-oriented instructions (extended instruction set enabled) example instruction: addwf, f, d, a (opcode: 0010 01da ffff ffff ) when a = 0 and f ? 60h: the instruction executes in direct forced mode. ?f? is interpreted as a location in the access ram between 060h and fffh. this is the same as locations, f60h to fffh (bank 15), of data memory. locations below 060h are not available in this addressing mode. when a = 0 and f ??? 5fh: the instruction executes in indexed literal offset mode. ?f? is interpreted as an offset to the address value in fsr2. the two are added together to obtain the address of the target register for the instruction. the address can be anywhere in the data memory space. note that in this mode, the correct syntax is now: addwf [k], d where ?k? is the same as ?f?. when a = 1 (all values of f): the instruction executes in direct mode (also known as direct long mode). ?f? is interpreted as a location in one of the 16 banks of the data memory space. the bank is designated by the bank select register (bsr). the address can be in any implemented bank in the data memory space. 000h 060h 100h f00h f40h fffh valid range 00h 60h ffh data memory access ram bank 0 bank 1 through bank 14 bank 15 sfrs 000h 060h 100h f00h f40h fffh data memory bank 0 bank 1 through bank 14 bank 15 sfrs fsr2h fsr2l ffffffff 001001da ffffffff 001001da 000h 060h 100h f00h f40h fffh data memory bank 0 bank 1 through bank 14 bank 15 sfrs for ?f? bsr 00000000
? 2012 microchip technology inc. ds30575a-page 141 pic18f97j94 family 6.6.3 mapping the access bank in indexed literal offset mode the use of indexed literal offset addressing mode effectively changes how the lower part of access ram (00h to 5fh) is mapped. rather than containing just the contents of the bottom part of bank 0, this mode maps the contents from bank 0 and a user-defined ?window? that can be located anywhere in the data memory space. the value of fsr2 establishes the lower boundary of the addresses mapped into the window, while the upper boundary is defined by fsr2 plus 95 (5fh). addresses in the access ram above 5fh are mapped as previously described. (see section 6.3.2 ?access bank? .) an example of access bank remapping in this addressing mode is shown in figure 6-10 . remapping the access bank applies only to operations using the indexed literal offset mode. operations that use the bsr (access ram bit = 1 ) will continue to use direct addressing as before. any indirect or indexed addressing operation that explicitly uses any of the indirect file operands (including fsr2) will continue to operate as standard indirect addressing. any instruc- tion that uses the access bank, but includes a register address of greater than 05fh, will use direct addressing and the normal access bank map. 6.6.4 bsr in indexed literal offset mode although the access bank is remapped when the extended instruction set is enabled, the operation of the bsr remains unchanged. direct addressing, using the bsr to select the data memory bank, operates in the same manner as previously described. figure 6-10: remapping the access bank with indexed literal offset addressing data memory 000h 100h 200h f60h f00h fffh bank 1 bank 15 bank 2 through bank 14 sfrs 05fh addwf f, d, a fsr2h:fsr2l = 120h locations in the region from the fsr2 pointer (120h) to the pointer plus 05fh (17fh) are mapped to the bottom of the access ram (000h-05fh). special function registers at f60h through fffh are mapped to 60h through ffh, as usual. bank 0 addresses below 5fh are not available in this mode. they can still be addressed by using the bsr. access bank 00h ffh bank 0 sfrs bank 1 ?window? not accessible window example situation: 120h 17fh 5fh 60h
pic18f97j94 family ds30575a-page 142 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 143 pic18f97j94 family 7.0 flash program memory the flash program memory is readable, writable and erasable during normal operation over the entire v dd range. a read from program memory is executed on 1 byte at a time. a write to program memory is executed on blocks of 64 bytes at a time or 2 bytes at a time. program memory is erased in blocks of 512 bytes at a time. a bulk erase operation may not be issued from user code. writing or erasing program memory will cease instruction fetches until the operation is complete. the program memory cannot be accessed during the write or erase, therefore, code cannot execute. an internal programming timer terminates program memory writes and erases. a value written to program memory does not need to be a valid instruction. executing a program memory location that forms an invalid instruction results in a nop . 7.1 table reads and table writes in order to read and write program memory, there are two operations that allow the processor to move bytes between the program memory space and the data ram: ? table read ( tblrd ) ? table write ( tblwt ) the program memory space is 16 bits wide, while the data ram space is 8 bits wide. table reads and table writes move data between these two memory spaces through an 8-bit register (tablat). table read operations retrieve data from program memory and place it into the data ram space. figure 7-1 shows the operation of a table read with program memory and data ram. table write operations store data from the data memory space into holding registers in program memory. the procedure to write the contents of the holding registers into program memory is detailed in section 7.5 ?writing to flash program memory? . figure 7-2 shows the operation of a table write with program memory and data ram. table operations work with byte entities. a table block containing data, rather than program instructions, is not required to be word-aligned. therefore, a table block can start and end at any byte address. if a table write is being used to write executable code into program memory, program instructions will need to be word-aligned. figure 7-1: table read operation table pointer (1) table latch (8-bit) program memory tblptrh tblptrl tablat tblptru instruction: tblrd * note 1: table pointer register points to a byte in program memory. program memory (tblptr)
pic18f97j94 family ds30575a-page 144 ? 2012 microchip technology inc. figure 7-2: table write operation 7.2 control registers several control registers are used in conjunction with the tblrd and tblwt instructions. these include: ? eecon1 register ? eecon2 register ? tablat register ? tblptr registers 7.2.1 eecon1 and eecon2 registers the eecon1 register ( register 7-1 ) is the control register for memory accesses. the eecon2 register is not a physical register; it is used exclusively in the memory write and erase sequences. reading eecon2 will read all ? 0 ?s. the wwprog bit, when set, will allow programming two bytes per word on the execution of the wr command. if this bit is cleared, the wr command will result in programming on a block of 64 bytes. the free bit, when set, will allow a program memory erase operation. when free is set, the erase operation is initiated on the next wr command. when free is clear, only writes are enabled. the wren bit, when set, will allow a write operation. on power-up, the wren bit is clear. the wrerr bit is set in hardware when the wr bit is set, and cleared when the internal programming timer expires and the write operation is complete. table pointer (1) table latch (8-bit) tblptrh tblptrl tablat program memory (tblptr) tblptru instruction: tblwt * note 1: the table pointer actually points to one of 64 holdi ng registers; the address of which is determined by tblptrl<5:0>. the process for physically writing data to the program memory array is discussed in section 7.5 ?writing to flash program memory? . holding registers program memory note: during normal operation, the wrerr is read as ? 1 ?. this can indicate that a write operation was prematurely terminated by a reset or a write operation was attempted improperly.
? 2012 microchip technology inc. ds30575a-page 145 pic18f97j94 family register 7-1: eecon1: eeprom co ntrol register 1 (access fa6h) u-0 u-0 r/w-0 r/w-0 r/w-x r/w-0 r/s-0 u-0 ? ? wwprog free wrerr ( 1 ) wren wr ? bit 7 bit 0 legend: s = settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5 wwprog: one word-wide program bit 1 = programs 2 bytes on the next wr command 0 = programs 64 bytes on the next wr command bit 4 free: flash erase enable bit 1 = performs an erase operation on the next wr command (cleared by hardware after completion of erase) 0 = performs write-only bit 3 wrerr: flash program error flag bit ( 1 ) 1 = a write operation is prematurely terminated (any reset during self-timed programming in normal operation or an improper write attempt) 0 = the write operation completed bit 2 wren: flash program write enable bit 1 = allows write cycles to flash program memory 0 = inhibits write cycles to flash program memory bit 1 wr: write control bit 1 = initiates a program memory erase cycle or write cycle (the operation is self-timed and the bit is cleared by hardware once the write is complete) the wr bit can only be set (not cleared) in software. 0 = write cycle is complete bit 0 unimplemented: read as ? 0 ? note 1: when a wrerr error occurs, the eepgd and cfgs bits are not cleared. this allows tracing of the error condition.
pic18f97j94 family ds30575a-page 146 ? 2012 microchip technology inc. 7.2.2 table latch register (tablat) the table latch (tablat) is an 8-bit register mapped into the special function register (sfr) space. the table latch register is used to hold 8-bit data during data transfers between program memory and data ram. 7.2.3 table pointer register (tblptr) the table pointer (tblptr) register addresses a byte within the program memory. the tblptr is comprised of three sfr registers: table pointer upper byte, table pointer high byte and table pointer low byte (tblptru:tblptrh:tblptrl). these three regis- ters join to form a 22-bit wide pointer. the low-order 21 bits allow the device to address up to 2 mbytes of program memory space. the 22 nd bit allows access to the device id, the user id and the configuration bits. the table pointer register, tblptr, is used by the tblrd and tblwt instructions. these instructions can update the tblptr in one of four ways, based on the table operation. these operations are shown in table 7-1 and only affect the low-order 21 bits. 7.2.4 table pointer boundaries tblptr is used in reads, writes and erases of the flash program memory. when a tblrd is executed, all 22 bits of the tblptr determine which byte is read from program memory into tablat. when a tblwt is executed, the seven least significant bits (lsbs) of the table pointer register (tblptr<6:0>) determine which of the 64 program memory holding registers is written to. when the timed write to program memory begins (via the wr bit), the 12 most significant bits (msbs) of the tblptr (tblptr<21:10>) determine which program memory block of 1024 bytes is written to. for more detail, see section 7.5 ?writing to flash program memory? . when an erase of program memory is executed, the 12 msbs of the table pointer register point to the 1024-byte block that will be erased. the lsbs are ignored. figure 7-3 describes the relevant boundaries of the tblptr based on flash program memory operations. table 7-1: table pointe r operations with tblrd and tblwt instructions figure 7-3: table pointer bo undaries based on operation example operation on table pointer tblrd* tblwt* tblptr is not modified tblrd*+ tblwt*+ tblptr is incremented after the read/write tblrd*- tblwt*- tblptr is decremented after the read/write tblrd+* tblwt+* tblptr is incremented before the read/write 21 16 15 87 0 table read ? tblptr<21:0> tblptrl tblptrh tblptru erase: tblptr<20:10> table write: tblptr<20:6>
? 2012 microchip technology inc. ds30575a-page 147 pic18f97j94 family 7.3 reading the flash program memory the tblrd instruction is used to retrieve data from program memory and places it into data ram. table reads from program memory are performed one byte at a time. the tblptr points to a byte address in program space. executing tblrd places the byte pointed to into tablat. in addition, the tblptr can be modified automatically for the next table read operation. the internal program memory is typically organized by words. the least significant bit of the address selects between the high and low bytes of the word. figure 7-4 shows the interface between the internal program memory and the tablat. figure 7-4: reads from flash program memory example 7-1: reading a flash program memory word (even byte address) program memory (odd byte address) tblrd tblptr = xxxxx1 fetch instruction register (ir) tblptr = xxxxx0 tablat read register movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the word movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl read_word tblrd*+ ; read into tablat and increment movf tablat, w ; get data movwf word_even tblrd*+ ; read into tablat and increment movf tablat, w ; get data movwf word_odd
pic18f97j94 family ds30575a-page 148 ? 2012 microchip technology inc. 7.4 erasing flash program memory the minimum erase block is 256 words or 512 bytes. only through the use of an external programmer, or through icsp control, can larger blocks of program memory be bulk erased. word erase in the flash array is not supported. when initiating an erase sequence from the microcon- troller itself, a block of 512 bytes of program memory is erased. the most significant 12 bits of the tblptr<21:10> point to the block being erased; tblptr<9:0> are ignored. the eecon1 register commands the erase operation. the wren bit must be set to enable write operations. the free bit is set to select an erase operation. for protection, the write initiate sequence for eecon2 must be used. a long write is necessary for erasing the internal flash. instruction execution is halted while in a long write cycle. the long write will be terminated by the internal programming timer. 7.4.1 flash program memory erase sequence the sequence of events for erasing a block of internal program memory location is: 1. load table pointer register with address of row being erased. 2. set the wren and free bits (eecon1<2,4>) to enable the erase operation. 3. disable interrupts. 4. write 55h to eecon2. 5. write 0aah to eecon2. 6. set the wr bit; this will begin the erase cycle. 7. the cpu will stall for the duration of the erase for t ie (see parameter d133b ). 8. re-enable interrupts. example 7-2: erasing a flash program memory row movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the memory block movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl erase_row bsf eecon1, wren ; enable write to memory bsf eecon1, free ; enable row erase operation bcf intcon, gie ; disable interrupts required movlw 0x55 sequence movwf eecon2 ; write 55h movlw 0xaa movwf eecon2 ; write 0aah bsf eecon1, wr ; start erase (cpu stall) bsf intcon, gie ; re-enable interrupts
? 2012 microchip technology inc. ds30575a-page 149 pic18f97j94 family 7.5 writing to flash program memory the programming block is 32 words or 64 bytes. programming one word or 2 bytes at a time is also sup- ported. table writes are used internally to load the holding registers needed to program the flash memory. there are 64 holding registers used by the table writes for programming. since the table latch (tablat) is only a single byte, the tblwt instruction may need to be executed 64 times for each programming operation (if wwprog = 0 ). all of the table write operations will essentially be short writes because only the holding registers are written. at the end of updating the 64 holding registers, the eecon1 register must be written to in order to start the programming operation with a long write. the long write is necessary for programming the internal flash. instruction execution is halted while in a long write cycle. the long write will be terminated by the internal programming timer. the on-chip timer controls the write time. the write/ erase voltages are generated by an on-chip charge pump, rated to operate over the voltage range of the device. figure 7-5: table writes to flash program memory 7.5.1 flash program memory write sequence the sequence of events for programming an internal program memory location should be: 1. read the 512 bytes into ram. 2. update the data values in ram as necessary. 3. load the table pointer register with the address being erased. 4. execute the erase procedure. 5. load the table pointer register with the address of the first byte being written, minus 1. 6. write the 64 bytes into the holding registers with auto-pre-increment. 7. set the wren bit (eecon1<2>) to enable byte writes. 8. disable the interrupts. 9. write 55h to eecon2. 10. write 0xaah to eecon2. 11. set the wr bit. this will begin the write cycle. the cpu will stall for duration of the write for t iw (see parameter d133a ). 12. re-enable the interrupts. 13. verify the memory (table read). an example of the required code is shown in example 7-3 on the following page 150 . note 1: unlike previous pic ? mcus, devices of the pic18f97j94 family do not reset the holding registers after a write occurs. the holding registers must be cleared or overwritten before a programming sequence. 2: to maintain the endurance of the program memory cells, each flash byte should not be programmed more than once between erase operations. before attempting to modify the contents of the target cell a second time, an erase of the target page, or a bulk erase of the entire memory, must be performed. tablat tblptr = xxxx3f tblptr = xxxxx1 tblptr = xxxxx0 write register tblptr = xxxxx2 program memory holding register holding register holding register holding register 8 8 8 8 note: before setting the wr bit, the table pointer address needs to be within the intended address range of the 64 bytes in the holding register.
pic18f97j94 family ds30575a-page 150 ? 2012 microchip technology inc. example 7-3: writing to flash program memory movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the memory block, minus 1 movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl erase_block bsf eecon1, wren ; enable write to memory bsf eecon1, free ; enable erase operation bcf intcon, gie ; disable interrupts movlw 55h movwf eecon2 ; write 55h movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start erase (cpu stall) bsf intcon, gie ; re-enable interrupts movlw d ? 8 ? movwf write_counter ; need to write 8 blocks of 64 to write ; one erase block of 512 restart buffer movlw d'64' movwf counter movlw buffer_addr_high ; point to buffer movwf fsr0h movlw buffer_addr_low movwf fsr0l fill_buffer ... ; read the new data from i2c, spi, ; psp, usart, etc. write_buffer movlw d?64 ; number of bytes in holding register movwf counter write_byte_to_hregs movff postinc0, wreg ; get low byte of buffer data movwf tablat ; present data to table latch tblwt+* ; write data, perform a short write ; to internal tblwt holding register. decfsz counter ; loop until buffers are full bra write_byte_to_hregs program_memory bsf eecon1, wren ; enable write to memory bcf intcon, gie ; disable interrupts movlw 55h required movwf eecon2 ; write 55h sequence movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start program (cpu stall) bsf intcon, gie ; re-enable interrupts bcf eecon1, wren ; disable write to memory decfsz write_counter ; done with one write cycle bra restart_buffer ; if not done replacing the erase block
? 2012 microchip technology inc. ds30575a-page 151 pic18f97j94 family 7.5.2 flash program memory write sequence (word programming) the pic18f97j94 family of devices has a feature that allows programming a single word (two bytes). this feature is enabled when the wwprog bit is set. if the memory location is already erased, the following sequence is required to enable this feature: 1. load the table pointer register with the address of the data to be written. (it must be an even address.) 2. write the 2 bytes into the holding registers by performing table writes. (do not post-increment on the second table write). 3. set the wren bit (eecon1<2>) to enable writes and the wwprog bit (eecon1<5>) to select word write mode. 4. disable interrupts. 5. write 55h to eecon2. 6. write 0aah to eecon2. 7. set the wr bit; this will begin the write cycle. 8. the cpu will stall for the duration of the write for t iw (see parameter d133a ). 9. re-enable interrupts. example 7-4: single-word writ e to flash program memory movlw code_addr_upper ; load tblptr with the base address movwf tblptru movlw code_addr_high movwf tblptrh movlw code_addr_low ; the table pointer must be loaded with an even address movwf tblptrl movlw data0 ; lsb of word to be written movwf tablat tblwt*+ movlw data1 ; msb of word to be written movwf tablat tblwt* ; the last table write must not increment the table pointer! the table pointer needs to point to the msb before starting the write operation. program_memory bsf eecon1, wwprog ; enable single word write bsf eecon1, wren ; enable write to memory bcf intcon, gie ; disable interrupts movlw 55h required movwf eecon2 ; write 55h sequence movlw 0aah movwf eecon2 ; write aah bsf eecon1, wr ; start program (cpu stall) bsf intcon, gie ; re-enable interrupts bcf eecon1, wwprog ; disable single word write bcf eecon1, wren ; disable write to memory
pic18f97j94 family ds30575a-page 152 ? 2012 microchip technology inc. 7.5.3 write verify depending on the application, good programming practice may dictate that the value written to the memory should be verified against the original value. this should be used in applications where excessive writes can stress bits near the specification limit. 7.5.4 unexpected termination of write operation if a write is terminated by an unplanned event, such as loss of power or an unexpected reset, the memory location just programmed should be verified and repro- grammed if needed. if the write operation is interrupted by a mclr reset, or a wdt time-out reset during nor- mal operation, the user can check the wrerr bit and rewrite the location(s) as needed 7.6 flash program operation during code protection see section 28.4.5 ?program verification and code protection? for details on code protection of flash program memory.
? 2012 microchip technology inc. ds30575a-page 153 pic18f97j94 family 8.0 external memory bus the external memory bus (emb) allows the device to access external memory devices (such as flash, eprom or sram) as program or data memory. it supports both 8 and 16-bit data width modes, and three address widths of up to 20 bits. the bus is implemented with 28 pins, multiplexed across four i/o ports. three ports (portd, porte and porth) are multiplexed with the address/data bus for a total of 20 available lines, while portj is multiplexed with the bus control signals. a list of the pins and their functions is provided in table 8-1 . table 8-1: pic18f97j94 family exte rnal bus ? i/o port functions note: the external memory bus is not implemented on 64-pin devices. name port bit external memory bus function rd0/ad0 portd 0 address bit 0 or data bit 0 rd1/ad1 portd 1 address bit 1 or data bit 1 rd2/ad2 portd 2 address bit 2 or data bit 2 rd3/ad3 portd 3 address bit 3 or data bit 3 rd4/ad4 portd 4 address bit 4 or data bit 4 rd5/ad5 portd 5 address bit 5 or data bit 5 rd6/ad6 portd 6 address bit 6 or data bit 6 rd7/ad7 portd 7 address bit 7 or data bit 7 re0/ad8 porte 0 address bit 8 or data bit 8 re1/ad9 porte 1 address bit 9 or data bit 9 re2/ad10 porte 2 address bit 10 or data bit 10 re3/ad11 porte 3 address bit 11 or data bit 11 re4/ad12 porte 4 address bit 12 or data bit 12 re5/ad13 porte 5 address bit 13 or data bit 13 re6/ad14 porte 6 address bit 14 or data bit 14 re7/ad15 porte 7 address bit 15 or data bit 15 rh0/a16 porth 0 address bit 16 rh1/a17 porth 1 address bit 17 rh2/a18 porth 2 address bit 18 rh3/a19 porth 3 address bit 19 rj0/ale portj 0 address latch enable (ale) control pin rj1/oe portj 1 output enable (oe ) control pin rj2/wrl portj 2 write low (wrl ) control pin rj3/wrh portj 3 write high (wrh ) control pin rj4/ba0 portj 4 byte address bit 0 (ba0) rj5/ce portj 5 chip enable (ce ) control pin rj6/lb portj 6 lower byte enable (lb ) control pin rj7/ub portj 7 upper byte enable (ub ) control pin note: for the sake of clarity, only i/o port and external bus assignments are shown here. one or more additional multiplexed features may be available on some pins.
pic18f97j94 family ds30575a-page 154 ? 2012 microchip technology inc. 8.1 external memory bus control the operation of the interface is controlled by the memcon register ( register 8-1 ). this register is available in all program memory operating modes, except microcontroller mode. in this mode, the register is disabled and cannot be written to. the ebdis bit (memcon<7>) controls the operation of the bus and related port functions. clearing ebdis enables the interface and disables the i/o functions of the ports, as well as any other functions multiplexed to those pins. setting the bit enables the i/o ports and other functions, but allows the interface to override everything else on the pins when an external memory operation is required. by default, the external bus is always enabled and disables all other i/o. the operation of the ebdis bit is also influenced by the program memory mode being used. this is discussed in more detail in section 8.5 ?program memory modes and the external memory bus? . the waitx bits allow for the addition of wait states to external memory operations. the use of these bits is discussed in section 8.3 ?wait states? . the wmx bits select the particular operating mode used when the bus is operating in 16-bit data width mode. this is discussed in more detail in section 8.6 ?16-bit data width modes? . these bits have no effect when an 8-bit data width mode is selected. register 8-1: memcon: external memory bus control register ( 1 ) r/w-0 u-0 r/w-0 r/w-0 u-0 u-0 r/w-0 r/w-0 ebdis ?wait1wait0 ? ?wm1wm0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ebdis : external bus disable bit 1 = external bus is enabled when microcontroller accesses external memory; otherwise, all external bus drivers are mapped as i/o ports 0 = external bus is always enabled, i/o ports are disabled bit 6 unimplemented : read as ? 0 ? bit 5-4 wait<1:0>: table reads and writes bus cycle wait count bits 11 = table reads and writes will wait 0 t cy 10 = table reads and writes will wait 1 t cy 01 = table reads and writes will wait 2 t cy 00 = table reads and writes will wait 3 t cy bit 3-2 unimplemented : read as ? 0 ? bit 1-0 wm<1:0>: tblwt operation with 16-bit data bus width select bits 1x = word write mode: tablat word output, wrh is active when tablat is written 01 = byte select mode: tablat data is copied on both msb and lsb, wrh and (ub or lb ) will activate 00 = byte write mode: tablat data is copied on both msb and lsb, wrh or wrl will activate note 1: this register is unimplemented on 64-pin devices, read as ? 0 ?.
? 2012 microchip technology inc. ds30575a-page 155 pic18f97j94 family 8.2 address and data width the pic18f97j94 family of devices can be indepen- dently configured for different address and data widths on the same memory bus. both address and data width are set by configuration bits in the config5l register. as configuration bits, this means that these options can only be configured by programming the device and are not controllable in software. the bw bit selects an 8-bit or 16-bit data bus width. setting this bit (default) selects a data width of 16 bits. the abw<1:0> bits determine both the program mem- ory operating mode and the address bus width. the available options are 20-bit, 16-bit and 12-bit, as well as microcontroller mode (external bus disabled). selecting a 16-bit or 12-bit width makes a correspond- ing number of high-order lines available for i/o functions. these pins are no longer affected by the setting of the ebdis bit. for example, selecting a 16-bit addressing mode (abw<1:0> = 01 ) disables a<19:16> and allows porth<3:0> to function without interruptions from the bus. using the smaller address widths allows users to tailor the memory bus to the size of the external memory space for a particular design while freeing up pins for dedicated i/o operation. because the abwx bits have the effect of disabling pins for memory bus operations, it is important to always select an address width at least equal to the data width. if a 12-bit address width is used with a 16-bit data width, the upper four bits of data will not be available on the bus. all combinations of address and data widths require multiplexing of address and data information on the same lines. the address and data multiplexing, as well as i/o ports made available by the use of smaller address widths, are summarized in ta b l e 8 - 2 . 8.2.1 address shifting on the external bus by default, the address presented on the external bus is the value of the pc. in practical terms, this means that addresses in the external memory device, below the top of on-chip memory, are unavailable to the microcontroller. to access these physical locations, the glue logic between the microcontroller and the external memory must somehow translate addresses. to simplify the interface, the external bus offers an extension of extended microcontroller mode that automatically performs address shifting. this feature is controlled by the eashft configuration bit. setting this bit offsets addresses on the bus by the size of the microcontroller?s on-chip program memory and sets the bottom address at 0000h. this allows the device to use the entire range of physical addresses of the external memory. 8.2.2 21-bit addressing as an extension of 20-bit address width operation, the external memory bus can also fully address a 2-mbyte memory space. this is done by using the bus address bit 0 (ba0) control line as the least significant bit of the address. the ub and lb control signals may also be used with certain memory devices to select the upper and lower bytes within a 16-bit wide data word. this addressing mode is available in both 8-bit and certain 16-bit data width modes. additional details are provided in section 8.6.3 ?16-bit byte select mode? and section 8.7 ?8-bit data width mode? . table 8-2: address and data lines for different address and data widths data width address width multiplexed data and address lines (and corresponding ports) address only lines (and corresponding ports) ports available for i/o 8-bit 12-bit ad<7:0> (portd<7:0>) ad<11:8> (porte<3:0>) porte<7:4>, all of porth 16-bit ad<15:8> (porte<7:0>) all of porth 20-bit a<19:16>, ad<15:8> (porth<3:0>, porte<7:0>) ? 16-bit 16-bit ad<15:0> (portd<7:0>, porte<7:0>) ? all of porth 20-bit a<19:16> (porth<3:0>) ?
pic18f97j94 family ds30575a-page 156 ? 2012 microchip technology inc. 8.3 wait states while it may be assumed that external memory devices will operate at the microcontroller clock rate, this is often not the case. in fact, many devices require longer times to write or retrieve data than the time allowed by the execution of table read or table write operations. to compensate for this, the external memory bus can be configured to add a fixed delay to each table opera- tion using the bus. wait states are enabled by setting the wait configuration bit. when enabled, the amount of delay is set by the wait<1:0> bits (memcon<5:4>). the delay is based on multiples of microcontroller instruction cycle time and is added following the instruction cycle when the table operation is executed. the range is from no delay to 3 t cy (default value). 8.4 port pin weak pull-ups with the exception of the upper address lines, a<19:16>, the pins associated with the external mem- ory bus are equipped with weak pull-ups. the pull-ups are controlled by the upper nibble of the padcfg register (padcfg<7:4>). they are named rdpu, repu, rhpu and rjpu, and control pull-ups on portd, porte, porth and portj, respectively. setting one of these bits enables the corresponding pull-ups for that port. all pull-ups are disabled by default on all device resets. in extended microcontroller mode, the port pull-ups can be useful in preserving the memory state on the external bus while the bus is temporarily disabled (ebdis = 1 ). 8.5 program memory modes and the external memory bus the pic18f97j94 family of devices is capable of operating in one of two program memory modes, using combinations of on-chip and external program memory. the functions of the multiplexed port pins depend on the program memory mode selected, as well as the setting of the ebdis bit. in microcontroller mode, the bus is not active and the pins have their port functions only. writes to the memcom register are not permitted. the reset value of ebdis (? 0 ?) is ignored and the abwx pins behave as i/o ports. in extended microcontroller mode, the external program memory bus shares i/o port functions on the pins. when the device is fetching or doing table read/table write operations on the external program memory space, the pins will have the external bus function. if the device is fetching and accessing internal program memory locations only, the ebdis control bit will change the pins from external memory to i/o port functions. when ebdis = 0 , the pins function as the external bus. when ebdis = 1 , the pins function as i/o ports. if the device fetches or accesses external memory while ebdis = 1 , the pins will switch to the external bus. if the ebdis bit is set by a program executing from external memory, the action of setting the bit will be delayed until the program branches into the internal memory. at that time, the pins will change from external bus to i/o ports. if the device is executing out of internal memory when ebdis = 0 , the memory bus address/data and control pins will not be active. they will go to a state where the active address/data pins are tri-state; the ce , oe , wrh , wrl , ub and lb signals are ? 1 ?, and ale and ba0 are ? 0 ?. note that only those pins associated with the current address width are forced to tri-state; the other pins continue to function as i/o. in the case of 16-bit address width, for example, only ad<15:0> (portd and porte) are affected; a<19:16> (porth<3:0>) continue to function as i/o. in all external memory modes, the bus takes priority over any other peripherals that may share pins with it. this includes the parallel master port and serial communication modules which would otherwise take priority over the i/o port. 8.6 16-bit data width modes in 16-bit data width mode, the external memory interface can be connected to external memories in three different configurations: ? 16-bit byte write ?16-bit word write ? 16-bit byte select the configuration to be used is determined by the wm<1:0> bits in the memcon register (memcon<1:0>). these three different configurations allow the designer maximum flexibility in using both 8-bit and 16-bit devices with 16-bit data. for all 16-bit modes, the address latch enable (ale) pin indicates that the address bits, ad<15:0>, are avail- able on the external memory interface bus. following the address latch, the output enable (oe ) signal will enable both bytes of program memory at once to form a 16-bit instruction word. the chip enable (ce signal) is active at any time that the microcontroller accesses external memory, whether reading or writing; it is inactive (asserted high) whenever the device is in sleep mode. in byte select mode, jedec standard flash memories will require ba0 for the byte address line and one i/o line to select between byte and word mode. the other 16-bit modes do not need ba0. jedec standard static ram memories will use the ub or lb signals for byte selection.
? 2012 microchip technology inc. ds30575a-page 157 pic18f97j94 family 8.6.1 16-bit byte write mode figure 8-1 shows an example of 16-bit byte write mode for pic18f97j94 family devices. this mode is used for two separate 8-bit memories connected for 16-bit operation. this generally includes basic eprom and flash devices. it allows table writes to byte-wide external memories. during a tblwt instruction cycle, the tablat data is presented on the upper and lower bytes of the ad<15:0> bus. the appropriate wrh or wrl control line is strobed on the lsb of the tblptr. figure 8-1: 16-bit byte write mode example ad<7:0> a<19:16> (1) ale d<15:8> 373 a d<7:0> a<19:0> a d<7:0> 373 oe wrh oe oe wr (2) wr (2) ce ce note 1: upper order address lines are used only for 20-bit address widths. 2: this signal only applies to table writes. see section 7.1 ?table reads and table writes? . wrl d<7:0> (lsb) (msb) d<7:0> ad<15:8> address bus data bus control lines ce pic18f97j94
pic18f97j94 family ds30575a-page 158 ? 2012 microchip technology inc. 8.6.2 16-bit word write mode figure 8-2 shows an example of 16-bit word write mode for pic18f97j94 family devices. this mode is used for word-wide memories, which includes some of the eprom and flash-type memories. this mode allows opcode fetches and table reads from all forms of 16-bit memory, and table writes to any type of word-wide external memories. this method makes a distinction between tblwt cycles to even or odd addresses. during a tblwt cycle to an even address (tblptr<0> = 0 ), the tablat data is transferred to a holding latch and the external address data bus is tri-stated for the data portion of the bus cycle. no write signals are activated. during a tblwt cycle to an odd address (tblptr<0> = 1 ), the tablat data is presented on the upper byte of the ad<15:0> bus. the contents of the holding latch are presented on the lower byte of the ad<15:0> bus. the wrh signal is strobed for each write cycle; the wrl pin is unused. the signal on the ba0 pin indicates the lsb of the tblptr, but it is left unconnected. instead, the ub and lb signals are active to select both bytes. the obvious limitation to this method is that the table write must be done in pairs on a specific word boundary to correctly write a word location. figure 8-2: 16-bit word write mode example ad<7:0> ad<15:8> ale 373 a<20:1> 373 oe wrh a<19:16> (1) a d<15:0> oe wr (2) ce d<15:0> jedec word eprom memory address bus data bus control lines note 1: upper order address lines are used only for 20-bit address widths. 2: this signal only applies to table writes. see section 7.1 ?table reads and table writes? . ce pic18f97j94
? 2012 microchip technology inc. ds30575a-page 159 pic18f97j94 family 8.6.3 16-bit byte select mode figure 8-3 shows an example of 16-bit byte select mode. this mode allows table write operations to word-wide external memories with byte selection capability. this generally includes both word-wide flash and sram devices. during a tblwt cycle, the tablat data is presented on the upper and lower byte of the ad<15:0> bus. the wrh signal is strobed for each write cycle; the wrl pin is not used. the ba0 or ub /lb signals are used to select the byte to be written, based on the least significant bit of the tblptr register. flash and sram devices use different control signal combinations to implement byte select mode. jedec standard flash memories require that a controller i/o port pin be connected to the memory?s byte/word pin to provide the select signal. they also use the ba0 signal from the controller as a byte address. jedec standard static ram memories, on the other hand, use the ub or lb signals to select the byte. figure 8-3: 16-bit byte select mode example ad<7:0> ad<15:8> ale 373 a<20:1> 373 oe wrh a<19:16> (2) wrl ba0 jedec word a d<15:0> a<20:1> ce d<15:0> i/o oe wr (1) a0 byte/word flash memory jedec word a d<15:0> ce d<15:0> oe wr (1) lb ub sram memory lb ub 138 (3) address bus data bus control lines note 1: this signal only applies to table writes. see section 7.1 ?table reads and table writes? . 2: upper order address lines are us ed only for 20-bit address width. 3: demultiplexing is only required when mu ltiple memory devices are accessed. pic18f97j94
pic18f97j94 family ds30575a-page 160 ? 2012 microchip technology inc. 8.6.4 16-bit mode timing the presentation of control signals on the external memory bus is different for the various operating modes. typical signal timing diagrams are shown in figure 8-4 and figure 8-5 . figure 8-4: external me mory bus timing for tblrd (extended microcont roller mode) figure 8-5: external me mory bus timing for sleep (extended microco ntroller mode) q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 a<19:16> ale oe ad<15:0> ce opcode fetch opcode fetch opcode fetch tblrd * tblrd cycle 1 addlw 55h from 000100h q2 q1 q3 q4 0ch cf33h tblrd 92h from 199e67h 9256h from 000104h memory cycle instruction execution inst(pc ? 2) tblrd cycle 2 movlw 55h from 000102h movlw q2 q1 q3 q4 q2 q1 q3 q4 a<19:16> ale oe 3aaah ad<15:0> 00h 00h ce opcode fetch opcode fetch sleep sleep from 007554h q1 bus inactive 0003h 3aabh 0e55h memory cycle instruction execution inst(pc ? 2) sleep mode, movlw 55h from 007556h
? 2012 microchip technology inc. ds30575a-page 161 pic18f97j94 family 8.7 8-bit data width mode in 8-bit data width mode, the external memory bus operates only in multiplexed mode; that is, data shares the 8 least significant bits of the address bus. figure 8-6 shows an example of 8-bit multiplexed mode for 100-pin devices. this mode is used for a single, 8-bit memory, connected for 16-bit operation. the instructions will be fetched as two 8-bit bytes on a shared data/address bus. the two bytes are sequen- tially fetched within one instruction cycle (t cy ). therefore, the designer must choose external memory devices, according to timing calculations based on 1/2 t cy (2 times the instruction rate). for proper mem- ory speed selection, glue logic propagation delay times must be considered, along with setup and hold times. the address latch enable (ale) pin indicates that the address bits, ad<15:0>, are available on the external memory bus interface. the output enable (oe ) signal will enable one byte of program memory for a portion of the instruction cycle, then ba0 will change and the second byte will be enabled to form the 16-bit instruc- tion word. the least significant bit of the address, ba0, must be connected to the memory devices in this mode. the chip enable (ce ) signal is active at any time that the microcontroller accesses external memory, whether reading or writing. it is inactive (asserted high) whenever the device is in sleep mode. this generally includes basic eprom and flash devices. it allows table writes to byte-wide external memories. during a tblwt instruction cycle, the tablat data is presented on the upper and lower bytes of the ad<15:0> bus. the appropriate level of the ba0 control line is strobed on the lsb of the tblptr. figure 8-6: 8-bit multiplexed mode example ad<7:0> a<19:16> (1) ale d<15:8> 373 a<19:0> a d<7:0> oe oe wr (2) ce note 1: upper order address bits are only used for 20-bit address width. the upper ad byte is used for all address widths except 8-bit. 2: this signal only applies to table writes. see section 7.1 ?table reads and table writes? . wrl d<7:0> ad<15:8> (1) address bus data bus control lines ce a0 ba0 pic18f97j94
pic18f97j94 family ds30575a-page 162 ? 2012 microchip technology inc. 8.7.1 8-bit mode timing the presentation of control signals on the external memory bus is different for the various operating modes. typical signal timing diagrams are shown in figure 8-7 and figure 8-8 . figure 8-7: external me mory bus timing for tblrd (extended microcont roller mode) figure 8-8: external me mory bus timing for sleep (extended microcont roller mode) q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 a<19:16> ale oe ad<7:0> ce opcode fetch opcode fetch opcode fetch tblrd * tblrd cycle 1 addlw 55h from 000100h q2 q1 q3 q4 0ch 33h tblrd 92h from 199e67h 92h from 000104h memory cycle instruction execution inst(pc ? 2) tblrd cycle 2 movlw 55h from 000102h movlw ad<15:8> cfh q2 q1 q3 q4 q2 q1 q3 q4 a<19:16> ale oe aah ad<7:0> 00h 00h ce opcode fetch opcode fetch sleep sleep from 007554h q1 bus inactive 00h abh 55h memory cycle instruction execution inst(pc ? 2) sleep mode, movlw 55h from 007556h ad<15:8> 3ah 3ah 03h 0eh ba0
? 2012 microchip technology inc. ds30575a-page 163 pic18f97j94 family 8.8 operation in power-managed modes in alternate, power-managed run modes, the external bus continues to operate normally. if a clock source with a lower speed is selected, bus operations will run at that speed. in these cases, excessive access times for the external memory may result if wait states have been enabled and added to external memory opera- tions. if operations in a lower power run mode are anticipated, users should provide in their applications for adjusting memory access times at the lower clock speeds. in sleep and idle modes, the microcontroller core does not need to access data; bus operations are sus- pended. the state of the external bus is frozen, with the address/data pins and most of the control pins holding at the same state they were in when the mode was invoked. the only potential changes are to the ce , lb and ub pins, which are held at logic high. table 8-3: registers associated with the external memory bus name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 memcon ( 1 ) ebdis ?wait1wait0 ? ?wm1wm0 padcfg rdpu repu rfpu rgpu rhpu rjpu rkpu rlpu pmd4 cmp1md cmp2md cmp3md usbmd iocmd lvdmd ? embmd legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used during external memory bus access. note 1: this register is unimplemented on 64-pin devices read as ? 0 ?.
pic18f97j94 family ds30575a-page 164 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 165 pic18f97j94 family 9.0 8 x 8 hardware multiplier 9.1 introduction all pic18 devices include an 8 x 8 hardware multiplier as part of the alu. the multiplier performs an unsigned operation and yields a 16-bit result that is stored in the product register pair, prodh:prodl. the multiplier?s operation does not affect any flags in the status register. making multiplication a hardware operation allows it to be completed in a single instruction cycle. this has the advantages of higher computational throughput and reduced code size for multiplication algorithms and allows pic18 devices to be used in many applications previously reserved for digital-signal processors. a comparison of various hardware and software multiply operations, along with the savings in memory and execution time, is shown in ta b l e 9 - 1 . 9.2 operation example 9-1 shows the instruction sequence for an 8 x 8 unsigned multiplication. only one instruction is required when one of the arguments is already loaded in the wreg register. example 9-2 shows the sequence to do an 8 x 8 signed multiplication. to account for the sign bits of the argu- ments, each argument?s most significant bit (msb) is tested and the appropriate subtractions are done. example 9-1: 8 x 8 unsigned multiply routine example 9-2: 8 x 8 signed multiply routine table 9-1: performance comparison for v arious multiply operations movf arg1, w ; mulwf arg2 ; arg1 * arg2 -> ; prodh:prodl movf arg1, w mulwf arg2 ; arg1 * arg2 -> ; prodh:prodl btfsc arg2, sb ; test sign bit subwf prodh, f ; prodh = prodh ; - arg1 movf arg2, w btfsc arg1, sb ; test sign bit subwf prodh, f ; prodh = prodh ; - arg2 routine multiply method program memory (words) cycles (max) time @ 64 mhz @ 48 mhz @ 10 mhz @ 4 mhz 8 x 8 unsigned without hardware multiply 13 69 4.3 ? s5.7 ? s27.6 ? s69 ? s hardware multiply 1 1 62.5 ns 83.3 ns 400 ns 1 ? s 8 x 8 signed without hardware multiply 33 91 5.6 ? s7.5 ? s36.4 ? s91 ? s hardware multiply 6 6 375 ns 500 ns 2.4 ? s6 ? s 16 x 16 unsigned without hardware multiply 21 242 15.1 ? s20.1 ? s96.8 ? s 242 ? s hardware multiply 28 28 1.7 ? s2.3 ? s11.2 ? s28 ? s 16 x 16 signed without hardware multiply 52 254 15.8 ? s21.2 ? s 101.6 ? s 254 ? s hardware multiply 35 40 2.5 ? s3.3 ? s16.0 ? s40 ? s
pic18f97j94 family ds30575a-page 166 ? 2012 microchip technology inc. example 9-3 shows the sequence to do a 16 x 16 unsigned multiplication. equation 9-1 shows the algorithm that is used. the 32-bit result is stored in four registers (res3:res0). equation 9-1: 16 x 16 unsigned multiplication algorithm example 9-3: 16 x 16 unsigned multiply routine example 9-4 shows the sequence to do a 16 x 16 signed multiply. equation 9-2 shows the algorithm used. the 32-bit result is stored in four registers (res3:res0). to account for the sign bits of the arguments, the msb for each argument pair is tested and the appropriate subtractions are done. equation 9-2: 16 x 16 signed multiplication algorithm example 9-4: 16 x 16 signed multiply routine res3:res0 = arg1h:arg1l ? arg2h:arg2l = (arg1h ? arg2h ? 2 16 ) + (arg1h ? arg2l ? 2 8 ) + (arg1l ? arg2h ? 2 8 ) + (arg1l ? arg2l) movf arg1l, w mulwf arg2l ; arg1l * arg2l-> ; prodh:prodl movff prodh, res1 ; movff prodl, res0 ; ; movf arg1h, w mulwf arg2h ; arg1h * arg2h-> ; prodh:prodl movff prodh, res3 ; movff prodl, res2 ; ; movf arg1l, w mulwf arg2h ; arg1l * arg2h-> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; movf arg1h, w ; mulwf arg2l ; arg1h * arg2l-> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; res3:res0= arg1h:arg1l ? arg2h:arg2l = (arg1h ? arg2h ? 2 16 ) + (arg1h ? arg2l ? 2 8 ) + (arg1l ? arg2h ? 2 8 ) + (arg1l ? arg2l) + (-1 ? arg2h<7> ? arg1h:arg1l ? 2 16 ) + (-1 ? arg1h<7> ? arg2h:arg2l ? 2 16 ) movf arg1l, w mulwf arg2l ; arg1l * arg2l -> ; prodh:prodl movff prodh, res1 ; movff prodl, res0 ; ; movf arg1h, w mulwf arg2h ; arg1h * arg2h -> ; prodh:prodl movff prodh, res3 ; movff prodl, res2 ; ; movf arg1l, w mulwf arg2h ; arg1l * arg2h -> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; movf arg1h, w ; mulwf arg2l ; arg1h * arg2l -> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; btfss arg2h, 7 ; arg2h:arg2l neg? bra sign_arg1 ; no, check arg1 movf arg1l, w ; subwf res2 ; movf arg1h, w ; subwfb res3 ; sign_arg1 btfss arg1h, 7 ; arg1h:arg1l neg? bra cont_code ; no, done movf arg2l, w ; subwf res2 ; movf arg2h, w ; subwfb res3 ; cont_code :
? 2012 microchip technology inc. ds30575a-page 167 pic18f97j94 family 10.0 interrupts members of the pic18f97j94 family of devices have multiple interrupt sources and an interrupt priority feature that allows most interrupt sources to be assigned a high-priority level or a low-priority level. the high-priority interrupt vector is at 0008h and the low-priority interrupt vector is at 0018h. high-priority interrupt events will interrupt any low-priority interrupts that may be in progress. the registers for controlling interrupt operation are: ? rcon ?intcon ? intcon2 ? intcon3 ? pir1, pir2, pir3, pir4, pir5 and pir6 ? pie1, pie2, pie3, pie4, pie5 and pie6 ? ipr1, ipr2, ipr3, ipr5, ipr5 and ipr6 it is recommended that the microchip header files, sup- plied with mplab ? ide, be used for the symbolic bit names in these registers. this allows the assembler/compiler to automatically take care of the placement of these bits within the specified register. in general, interrupt sources have three bits to control their operation. they are: ? flag bit ? indicating that an interrupt event occurred ? enable bit ? enabling program execution to branch to the interrupt vector address when the flag bit is set ? priority bit ? specifying high priority or low priority 10.1 mid-range compatibility when the ipen bit is cleared (default state), the interrupt priority feature is disabled and interrupts are compatible with pic ? microcontroller mid-range devices. in compatibility mode, the interrupt priority bits of the iprx registers have no effect. the peie/giel bit of the intcon register is the global interrupt enable for the peripherals. the peie/giel bit disables only the peripheral interrupt sources and enables the peripheral interrupt sources when the gie/gieh bit is also set. the gie/gieh bit of the intcon register is the global interrupt enable which enables all non-peripheral interrupt sources and disables all interrupt sources, including the peripherals. all interrupts branch to address 0008h in compatibility mode. 10.2 10.2 interrupt priority the interrupt priority feature is enabled by setting the ipen bit of the rcon register. when interrupt priority is enabled the gie/gieh and peie/giel global interrupt enable bits of compatibility mode are replaced by the gieh high priority, and giel low priority, global interrupt enables. when set, the gieh bit of the intcon register enables all interrupts that have their associated iprx register or intconx register priority bit set (high priority). when clear, the gieh bit disables all interrupt sources including those selected as low priority. when clear, the giel bit of the intcon register disables only the interrupts that have their associated priority bit cleared (low priority). when set, the giel bit enables the low priority sources when the gieh bit is also set. when the interrupt flag, enable bit and appropriate global interrupt enable (gie) bit are all set, the interrupt will vector immediately to address 0008h for high priority, or 0018h for low priority, depending on level of the interrupting source?s priority bit. individual interrupts can be disabled through their corresponding interrupt enable bits. 10.3 10.3 interrupt response when an interrupt is responded to, the global interrupt enable bit is cleared to disable further interrupts. the gie/gieh bit is the global interrupt enable when the ipen bit is cleared. when the ipen bit is set, enabling interrupt priority levels, the gieh bit is the high priority global interrupt enable and the giel bit is the low priority global interrupt enable. high priority interrupt sources can interrupt a low priority interrupt. low priority interrupts are not processed while high priority interrupts are in progress. the return address is pushed onto the stack and the pc is loaded with the interrupt vector address (0008h or 0018h). once in the interrupt service routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits in the intconx and pirx registers. the interrupt flag bits must be cleared by software before re-enabling interrupts to avoid repeating the same interrupt. the ?return from interrupt? instruction, retfie, exits the interrupt routine and sets the gie/gieh bit (gieh or giel if priority levels are used), which re-enables interrupts.
pic18f97j94 family ds30575a-page 168 ? 2012 microchip technology inc. for external interrupt events, such as the int pins or the portb interrupt-on-change, the interrupt latency will be three to four instruction cycles. the exact latency is the same for one-cycle or two-cycle instructions. individual interrupt flag bits are set, regardless of the status of their corresponding enable bits or the global interrupt enable bit. note: do not use the movff instruction to modify any of the interrupt control registers while any interrupt is enabled. doing so may cause erratic microcontroller behavior.
? 2012 microchip technology inc. ds30575a-page 169 pic18f97j94 family figure 10-1: pic18f97j94 family interrupt logic tmr0ie gie/gieh peie/giel wake-up if in interrupt to cpu vector to location 0008h int2if int2ie int2ip int1if int1ie int1ip tmr0if tmr0ie tmr0ip rbif rbie rbip ipen tmr0if tmr0ip int1if int1ie int1ip int2if int2ie int2ip rbif rbie rbip int0if int0ie peie/giel interrupt to cpu vector to location ipen ipen 0018h pir1<7:0> pie1<7:0> ipr1<7:0> high-priority interrupt generation low-priority interrupt generation idle or sleep modes gie/gieh int3if int3ie int3ip int3if int3ie int3ip pir2<7,5:0> pie2<7,5:0> ipr2<7,5:0> pir3<7,5> pie3<7,5> ipr3<7,5> pir1<7:0> pie1<7:0> ipr1<7:0> pir2<7, 5:0> pie2<7, 5:0> ipr2< 7, 5:0 > pir3<7, 5:0> pie3<7, 5:0> ipr3< 7, 5:0 > ipen pir4<7:0> pie4<7:0> ipr4<7:0> pir5<7:0> pie5<7:0> ipr5<7:0> pir4<7:0> pie4<7:0> ipr4<7:0> pir5<7:0> pie5<7:0> ipr5<7:0> pir6<7:0> pie6<7:0> ipr6<7:0> pir6<7:0> pie6<7:0> ipr 6< 7:0>
pic18f97j94 family ds30575a-page 170 ? 2012 microchip technology inc. 10.4 intcon registers the intcon registers are readable and writable registers that contain various enable, priority and flag bits. note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling. register 10-1: intcon: interrupt control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 gie/gieh peie/giel tmr0ie int0ie iocie tmr0if int0if iocif bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 gie/gieh: global interrupt enable bit when ipen = 0 : 1 = enables all unmasked interrupts 0 = disables all interrupts including peripherals when ipen = 1 : 1 = enables all high-priority interrupts 0 = disables all interrupts including low priority bit 6 peie/giel: peripheral interrupt enable bit when ipen = 0 : 1 = enables all unmasked peripheral interrupts 0 = disables all peripheral interrupts when ipen = 1 : 1 = enables all low-priority peripheral interrupts 0 = disables all low-priority peripheral interrupts bit 5 tmr0ie: tmr0 overflow interrupt enable bit 1 = enables the tmr0 overflow interrupt 0 = disables the tmr0 overflow interrupt bit 4 int0ie: int0 external interrupt enable bit 1 = enables the int0 external interrupt 0 = disables the int0 external interrupt bit 3 iocie: i/o change interrupt enable bit 1 = enables the i/o port change interrupt 0 = disables the i/o port change interrupt bit 2 tmr0if: tmr0 overflow interrupt flag bit 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register has not overflowed bit 1 int0if: int0 external interrupt flag bit 1 = the int0 external interrupt occurred (must be cleared in software) 0 = the int0 external interrupt did not occur bit 0 iocif: i/o port change interrupt flag bit 1 = at least one of the ioc<7:0> pins changed state (must be cleared by clearing all the iocf bits in the ioc module) 0 = none of the ioc<7:0> pins have changed state
? 2012 microchip technology inc. ds30575a-page 171 pic18f97j94 family register 10-2: intcon2: in terrupt control register 2 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip iocip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rbpu : portb pull-up enable bit 1 = all portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg0: external interrupt 0 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 5 intedg1: external interrupt 1 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 4 intedg2: external interrupt 2 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 3 intedg3: external interrupt 3 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 2 tmr0ip: tmr0 overflow interrupt priority bit 1 =high priority 0 = low priority bit 1 int3ip: int3 external interrupt priority bit 1 =high priority 0 = low priority bit 0 iocip: rb port change interrupt priority bit 1 =high priority 0 = low priority note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling.
pic18f97j94 family ds30575a-page 172 ? 2012 microchip technology inc. register 10-3: intcon3: in terrupt control register 3 r/w-1 r/w-1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 int2ip: int2 external interrupt priority bit 1 =high priority 0 = low priority bit 6 int1ip: int1 external interrupt priority bit 1 =high priority 0 = low priority bit 5 int3ie: int3 external interrupt enable bit 1 = enables the int3 external interrupt 0 = disables the int3 external interrupt bit 4 int2ie: int2 external interrupt enable bit 1 = enables the int2 external interrupt 0 = disables the int2 external interrupt bit 3 int1ie: int1 external interrupt enable bit 1 = enables the int1 external interrupt 0 = disables the int1 external interrupt bit 2 int3if: int3 external interrupt flag bit 1 = the int3 external interrupt occurred (must be cleared in software) 0 = the int3 external interrupt did not occur bit 1 int2if: int2 external interrupt flag bit 1 = the int2 external interrupt occurred (must be cleared in software) 0 = the int2 external interrupt did not occur bit 0 int1if: int1 external interrupt flag bit 1 = the int1 external interrupt occurred (must be cleared in software) 0 = the int1 external interrupt did not occur note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling.
? 2012 microchip technology inc. ds30575a-page 173 pic18f97j94 family 10.5 pir registers the pir registers contain the individual flag bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are six peripheral interrupt request (flag) registers (pir1 through pir5). note 1: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit, gie (intcon<7>). 2: user software should ensure the appropriate interrupt flag bits are cleared prior to enabling an interrupt and after servicing that interrupt. register 10-4: pir1: peripheral interrupt request (flag) register 1 r/w-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 pspif adif rc1if tx1if ssp1if tmr1gif tmr2if tmr1if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pspif: parallel slave port read/write interrupt flag bit 1 = a read or write operation has taken place (must be cleared in software) 0 = no read or write operation has occurred bit 6 adif: a/d converter interrupt flag bit 1 = an a/d conversion completed (must be cleared in software) 0 = the a/d conversion is not complete bit 5 rc1if: eusart1 receive interrupt flag bit 1 = the eusart1 receive buffer, rcreg1, is full (cleared when rcreg1 is read) 0 = the eusart1 receive buffer is empty bit 4 tx1if: eusart1 transmit interrupt flag bit 1 = the eusart1 transmit buffer, txreg1, is empty (cleared when txreg1 is written) 0 = the eusart1 transmit buffer is full bit 3 ssp1if: master synchronous serial port 1 interrupt flag bit 1 = the transmission/reception is complete (must be cleared in software) 0 = waiting to transmit/receive bit 2 tmr1gif: timer1 gate interrupt flag bit 1 = timer gate interrupt occurred (must be cleared in software) 0 = no timer gate interrupt occurred bit 1 tmr2if: tmr2 to pr2 match interrupt flag bit 1 = tmr2 to pr2 match occurred (must be cleared in software) 0 = no tmr2 to pr2 match occurred bit 0 tmr1if: tmr1 overflow interrupt flag bit 1 = tmr1 register overflowed (must be cleared in software) 0 = tmr1 register did not overflow
pic18f97j94 family ds30575a-page 174 ? 2012 microchip technology inc. register 10-5: pir2: peripheral interrupt request (flag) register 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 oscfif ssp2if bcl2if usbif bcl1if hlvdif tmr3if tmr3gif bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 oscfif: oscillator fail interrupt flag bit 1 = device oscillator failed, clock input has changed to intosc (bit must be cleared in software) 0 = device clock operating bit 6 ssp2if: master synchronous serial port 2 interrupt flag bit 1 = the transmission/reception is complete (must be cleared in software) 0 = waiting to transmit/receive bit 5 bcl2if: bus collision interrupt flag bit 1 = a bus collision has occurred while the mssp1 module configured in i 2 c? master was transmitting (must be cleared in software) 0 = no bus collision occurred bit 4 usbif: oscillator fail interrupt flag bit 1 = usb requested an interrupt (must be cleared in software) 0 = no usb interrupt request bit 3 bcl1if: bus collision interrupt flag bit 1 = a bus collision occurred (bit must be cleared in software) 0 = no bus collision occurred bit 2 hlvdif: high/low-voltage detect interrupt flag bit 1 = a low-voltage condition occurred (bit must be cleared in software) 0 = the device voltage is above the regulator?s low-voltage trip point bit 1 tmr3if: tmr3 overflow interrupt flag bit 1 = tmr3 register overflowed (bit must be cleared in software) 0 = tmr3 register did not overflow bit 0 tmr3gif: tmr3 gate interrupt flag bit 1 = timer gate interrupt occurred (bit must be cleared in software) 0 = no timer gate interrupt occurred
? 2012 microchip technology inc. ds30575a-page 175 pic18f97j94 family register 10-6: pir3: peripheral interrupt request (flag) register 3 r/w-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 tmr5gif lcdif rc2if tx2if ctmuif ccp2if ccp1if rtccif bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr5gif: tmr5 gate interrupt flag bits 1 = tmr gate interrupt occurred (must be cleared in software) 0 = no tmr gate occurred bit 6 lcdif: lcd interrupt flag bit 1 = a write is allowed to the segment data registers 0 = a write is not allowed to the segment data register bit 5 rc2if: eusart2 receive interrupt flag bit 1 = the eusart2 receive buffer, rcreg2, is full (cleared when rcreg2 is read) 0 = the eusart2 receive buffer is empty bit 4 tx2if: eusart2 transmit interrupt flag bit 1 = the eusart2 transmit buffer, txreg2, is empty (cleared when txreg2 is written) 0 = the eusart2 transmit buffer is full bit 3 ctmuif: ctmu interrupt flag bit 1 = ctmu interrupt occurred (must be cleared in software) 0 = no ctmu interrupt occurred bit 2 ccp2if: ccp2 interrupt flag bit capture mode: 1 = a tmr1/tmr3 register capture occurred (must be cleared in software) 0 = no tmr1/tmr3 register capture occurred compare mode: 1 = a tmr1/tmr3 register compare match occurred (must be cleared in software) 0 = no tmr1/tmr3 register compare match occurred pwm mode: unused in this mode. bit 1 ccp1if: eccp1 interrupt flag bit capture mode: 1 = a tmr1/tmr3 register capture occurred (must be cleared in software) 0 = no tmr1/tmr3 register capture occurred compare mode: 1 = a tmr1/tmr3 register compare match occurred (must be cleared in software) 0 = no tmr1/tmr3 register compare match occurred pwm mode: unused in this mode. bit 0 rtccif: rtcc interrupt flag bit 1 = rtcc interrupt occurred (must be cleared in software) 0 = no rtcc interrupt occurred
pic18f97j94 family ds30575a-page 176 ? 2012 microchip technology inc. register 10-7: pir4: peripheral interrupt request (flag) register 4 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ccp10if ccp9if ccp8if ccp7if ccp6if ccp5if ccp4if eccp3if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ccp10if: ccp10 interrupt flag bits capture mode: 1 = a tmr register capture occurred (bit must be cleared in software) 0 = no tmr register capture occurred compare mode: 1 = a tmr register compare match occurred (must be cleared in software) 0 = no tmr register compare match occurred pwm mode: not used in pwm mode. bit 6 ccp9if: ccp9 interrupt flag bits capture mode: 1 = a tmr register capture occurred (bit must be cleared in software) 0 = no tmr register capture occurred compare mode: 1 = a tmr register compare match occurred (must be cleared in software) 0 = no tmr register compare match occurred pwm mode: not used in pwm mode. bit 5 ccp8if: ccp8 interrupt flag bits capture mode: 1 = a tmr register capture occurred (bit must be cleared in software) 0 = no tmr register capture occurred compare mode: 1 = a tmr register compare match occurred (must be cleared in software) 0 = no tmr register compare match occurred pwm mode: not used in pwm mode. bit 4 ccp7if: ccp7 interrupt flag bit 1 = interrupt flag bits capture mode: 1 = a tmr register capture occurred (bit must be cleared in software) 0 = no tmr register capture occurred compare mode: 1 = a tmr register compare match occurred (must be cleared in software) 0 = no tmr register compare match occurred pwm mode: not used in pwm mode.
? 2012 microchip technology inc. ds30575a-page 177 pic18f97j94 family bit 3 ccp6if: ccp6 interrupt flag bits capture mode: 1 = a tmr register capture occurred (bit must be cleared in software) 0 = no tmr register capture occurred compare mode: 1 = a tmr register compare match occurred (must be cleared in software) 0 = no tmr register compare match occurred pwm mode: not used in pwm mode. bit 2 ccp5if: ccp5 interrupt flag bits capture mode: 1 = a tmr register capture occurred (bit must be cleared in software) 0 = no tmr register capture occurred compare mode: 1 = a tmr register compare match occurred (must be cleared in software) 0 = no tmr register compare match occurred pwm mode: not used in pwm mode. bit 1 ccp4if: ccp4 interrupt flag bits capture mode: 1 = a tmr register capture occurred (bit must be cleared in software) 0 = no tmr register capture occurred compare mode: 1 = a tmr register compare match occurred (must be cleared in software) 0 = no tmr register compare match occurred pwm mode: not used in pwm mode. bit 0 eccp3if: eccp3 interrupt flag bits capture mode: 1 = a tmr register capture occurred (bit must be cleared in software) 0 = no tmr register capture occurred compare mode: 1 = a tmr register compare match occurred (must be cleared in software) 0 = no tmr register compare match occurred pwm mode: not used in pwm mode. register 10-7: pir4: peripheral interrupt request (flag) register 4 (continued)
pic18f97j94 family ds30575a-page 178 ? 2012 microchip technology inc. register 10-8: pir5: peripheral interrupt request (flag) register 5 u-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 ? actorsif actlockif tmr8if ? tmr6if tmr5if tmr4if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 actorsif: active clock tuning out-of-range interrupt flag bit 1 = active clock tuning out-of-range occurred 0 = active tuning out-of-range did not occur bit 5 actlockif: active clock tuning lock interrupt flag bit 1 = active clock tuning lock/unlock occurred 0 = active clock tuning lock/unlock did not occur bit 4 tmr8if: tmr8 to pr8 match interrupt flag bit 1 = tmr8 to pr8 match occurred (must be cleared in software) 0 = no tmr8 to pr8 match occurred bit 3 unimplemented: read as ? 0 ? bit 2 tmr6if: tmr6 to pr6 match interrupt flag bit 1 = tmr6 to pr6 match occurred (must be cleared in software) 0 = no tmr6 to pr6 match occurred bit 1 tmr5if: tmr5 overflow interrupt flag bit 1 = tmr5 register overflowed (must be cleared in software) 0 = tmr5 register did not overflow bit 0 tmr4if: tmr4 to pr4 match interrupt flag bit 1 = tmr4 to pr4 match occurred (must be cleared in software) 0 = no tmr4 to pr4 match occurred
? 2012 microchip technology inc. ds30575a-page 179 pic18f97j94 family register 10-9: pir6: peripheral interrupt request (flag) register 6 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 rc4if tx4if rc3if tx3if ? cmp3if cmp2if cmp1if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rc4if: eusart4 receive interrupt flag bit 1 = the eusart4 receive buffer is full (cleared by reading rcreg4) 0 = the eusart4 receive buffer is empty bit 6 tx4if : eusart4 transmit interrupt flag bit 1 = the eusart4 transmit buffer is empty (cleared by writing to txreg4) 0 = the eusart4 transmit buffer is full bit 5 rc3if : eusart3 receive interrupt flag bit 1 = the eusart3 receive buffer is full (cleared by reading rcreg3) 0 = the eusart3 receive buffer is empty bit 4 tx3if: eusart3 transmit interrupt flag bit 1 = the eusart3 transmit buffer is empty (cleared by writing to txreg3) 0 = the eusart3 transmit buffer is full bit 3 unimplemented: read as ? 0 ? bit 2 cmp3if: cmp3 interrupt flag bit 1 = cmp3 interrupt occurred (must be cleared in software) 0 = no cmp3 interrupt occurred bit 1 cmp2if: cmp2 interrupt flag bit 1 = cmp2 interrupt occurred (must be cleared in software) 0 = no cmp2 interrupt occurred bit 0 cmp1if: cm1 interrupt flag bit 1 = cmp1 interrupt occurred (must be cleared in software) 0 = no cmp1 interrupt occurred
pic18f97j94 family ds30575a-page 180 ? 2012 microchip technology inc. 10.6 pie registers the pie registers contain the individual enable bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are six peripheral interrupt enable registers (pie1 through pie6). when ipen (rcon<7>) = 0 , the peie bit must be set to enable any of these peripheral interrupts. register 10-10: pie1: peripheral interrupt enable register 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pspie adie rc1ie tx1ie ssp1ie tmr1gie tmr2ie tmr1ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pspie: parallel slave port read/write interrupt enable bit 1 = enables the psp read/write interrupt 0 = disables the psp read/write interrupt bit 6 adie: a/d converter interrupt enable bit 1 = enables the a/d interrupt 0 = disables the a/d interrupt bit 5 rc1ie: eusart1 receive interrupt enable bit 1 = enables the eusart1 receive interrupt 0 = disables the eusart1 receive interrupt bit 4 tx1ie: eusart1 transmit interrupt enable bit 1 = enables the eusart1 transmit interrupt 0 = disables the eusart1 transmit interrupt bit 3 ssp1ie: master synchronous serial port 1 interrupt enable bit 1 = enables the mssp1 interrupt 0 = disables the mssp1 interrupt bit 2 tmr1gie: tmr1 gate interrupt enable bit 1 = enables the gate 0 = disables the gate bit 1 tmr2ie: tmr2 to pr2 match interrupt enable bit 1 = enables the tmr2 to pr2 match interrupt 0 = disables the tmr2 to pr2 match interrupt bit 0 tmr1ie: tmr1 overflow interrupt enable bit 1 = enables the tmr1 overflow interrupt 0 = disables the tmr1 overflow interrupt
? 2012 microchip technology inc. ds30575a-page 181 pic18f97j94 family register 10-11: pie2: peripheral interrupt enable register 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 oscfie ssp2ie bcl2ie usbie bcl1ie hlvdie tmr3ie tmr3gie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 oscfie: oscillator fail interrupt enable bit 1 = enabled 0 = disabled bit 6 ssp2ie: master synchronous serial port 2 interrupt enable bit 1 = enables the mssp2 interrupt 0 = disables the mssp2 interrupt bit 5 bcl2ie: bus collision interrupt enable bit (mssp) 1 = enabled 0 = disabled bit 4 usbie: usb interrupt enable bit 1 = enabled 0 = disabled bit 3 bclie: bus collision interrupt enable bit 1 = enabled 0 = disabled bit 2 hlvdie: high/low-voltage detect interrupt enable bit 1 = enabled 0 = disabled bit 1 tmr3ie: tmr3 overflow interrupt enable bit 1 = enabled 0 = disabled bit 0 tmr3gie: timer3 gate interrupt enable bit 1 = enabled 0 = disabled
pic18f97j94 family ds30575a-page 182 ? 2012 microchip technology inc. register 10-12: pie3: peripheral interrupt enable register 3 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 tmr5gie lcdie rc2ie tx2ie ctmuie ccp2ie ccp1ie rtccie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr5gie: tmr5 gate interrupt enable bit 1 = enabled 0 = disabled bit 6 lcdie: lcd ready interrupt enable bit 1 = enabled 0 = disabled bit 5 rc2ie: eusart2 receive interrupt enable bit 1 = enabled 0 = disabled bit 4 tx2ie: eusart2 transmit interrupt enable bit 1 = enabled 0 = disabled bit 3 ctmuie: ctmu interrupt enable bit 1 = enabled 0 = disabled bit 2 ccp2ie: ccp2 interrupt enable bit 1 = enabled 0 = disabled bit 1 ccp1ie: eccp1 interrupt enable bit 1 = enabled 0 = disabled bit 0 rtccie: rtcc interrupt enable bit 1 = enabled 0 = disabled
? 2012 microchip technology inc. ds30575a-page 183 pic18f97j94 family register 10-13: pie4: peripheral interrupt enable register 4 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ccp10ie ccp9ie ccp8ie ccp7ie ccp6ie ccp5ie ccp4ie eccp3ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ccp10ie: ccp10 interrupt enable bit 1 = enabled 0 =disabled bit 6 ccp9ie: ccp9 interrupt enable bit 1 = enabled 0 =disabled bit 5 ccp8ie: ccp8 interrupt enable bit 1 = enabled 0 =disabled bit 4 ccp7ie: ccp7 interrupt enable bit 1 = enabled 0 =disabled bit 3 ccp6ie: ccp6 interrupt enable bit 1 = enabled 0 =disabled bit 2 ccp5ie: ccp5 interrupt flag bit 1 = enabled 0 =disabled bit 1 ccp4ie: ccp4 interrupt flag bit 1 = enabled 0 =disabled bit 0 eccp3ie: eccp3 interrupt flag bit 1 = enabled 0 =disabled
pic18f97j94 family ds30575a-page 184 ? 2012 microchip technology inc. register 10-14: pie5: peripheral interrupt enable register 5 u-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 ? actorsie actlockie tmr8ie ? tmr6ie tmr5ie tmr4ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 actorsie: active clock tuning out-of-range interrupt enable bit 1 = enables the active clock tuning out-of-range interrupt 0 = disables the active clock tuning out-of-range interrupt bit 5 actlockie: active clock tuning lock interrupt enable bit 1 = enables the active clock tuning lock/unlock interrupt 0 = disables the active clock tuning lock/unlock interrupt bit 4 tmr8ie: tmr8 to pr8 match interrupt enable bit 1 = enables the tmr8 to pr8 match interrupt 0 = disables the tmr8 to pr8 match interrupt bit 3 unimplemented: read as ? 0 ? bit 2 tmr6ie: tmr6 to pr6 match interrupt enable bit 1 = enables the tmr6 to pr6 match interrupt 0 = disables the tmr6 to pr6 match interrupt bit 1 tmr5ie: tmr5 overflow interrupt enable bit 1 = enables the tmr5 overflow interrupt 0 = disables the tmr5 overflow interrupt bit 0 tmr4ie: tmr4 to pr4 match interrupt enable bit 1 = enables the tmr4 to pr4 match interrupt 0 = disables the tmr4 to pr4 match interrupt
? 2012 microchip technology inc. ds30575a-page 185 pic18f97j94 family register 10-15: pie6: peripheral interrupt enable register 6 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 rc4ie tx4ie rc3ie tx3ie ? cmp3ie cmp2ie cmp1ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rc4ie: eusart4 receive interrupt enable bit 1 = enabled 0 =disabled bit 6 tx4ie: eusart4 transmit interrupt enable bit 1 = enabled 0 =disabled bit 5 rc34ie: eusart3 receive interrupt enable bit 1 = enabled 0 =disabled bit 4 tx3ie: eusart3 transmit interrupt enable bit 1 = enabled 0 =disabled bit 3 unimplemented: read as ? 0 ? bit 2 cmp3ie: comparator 3 interrupt enable bit 1 = enabled 0 =disabled bit 1 cmp2ie: comparator 2 interrupt enable bit 1 = enabled 0 =disabled bit 0 cmp1ie: comparator 1 interrupt enable bit 1 = enabled 0 =disabled
pic18f97j94 family ds30575a-page 186 ? 2012 microchip technology inc. 10.7 ipr registers the ipr registers contain the individual priority bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are six peripheral interrupt priority registers (ipr1 through ipr6). using the priority bits requires that the interrupt priority enable (ipen) bit (rcon<7>) be set. register 10-16: ipr1: peripheral interrupt priority register 1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 pspip adip rc1ip tx1ip ssp1ip tmr1gip tmr2ip tmr1ip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pspip: parallel slave port read/write interrupt priority bit 1 =high priority 0 = low priority bit 6 adip: a/d converter interrupt priority bit 1 =high priority 0 = low priority bit 5 rc1ip: eusart1 receive interrupt priority bit 1 =high priority 0 = low priority bit 4 tx1ip: eusart1 transmit interrupt priority bit 1 =high priority 0 = low priority bit 3 ssp1ip: master synchronous serial port 1 interrupt priority bit 1 =high priority 0 = low priority bit 2 tmr1gip: timer1 gate interrupt priority bit 1 =high priority 0 = low priority bit 1 tmr2ip: tmr2 to pr2 match interrupt priority bit 1 =high priority 0 = low priority bit 0 tmr1ip: tmr1 overflow interrupt priority bit 1 =high priority 0 = low priority
? 2012 microchip technology inc. ds30575a-page 187 pic18f97j94 family register 10-17: ipr2: peripheral interrupt priority register 2 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 oscfip ssp2ip bcl2ip usbip bcl1ip hlvdip tmr3ip tmr3gip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 oscfip: oscillator fail interrupt priority bit 1 =high priority 0 = low priority bit 6 ssp2ip: master synchronous serial port 2 interrupt priority bit 1 =high priority 0 = low priority bit 5 bcl2ip: bus collision interrupt priority bit (mssp) 1 =high priority 0 = low priority bit 4 usbip: usb interrupt priority bit 1 =high priority 0 = low priority bit 3 bcl1ip: bus collision interrupt priority bit 1 =high priority 0 = low priority bit 2 hlvdip: high/low-voltage detect interrupt priority bit 1 =high priority 0 = low priority bit 1 tmr3ip: tmr3 overflow interrupt priority bit 1 =high priority 0 = low priority bit 0 tmr3gip: tmr3 gate interrupt priority bit 1 =high priority 0 = low priority
pic18f97j94 family ds30575a-page 188 ? 2012 microchip technology inc. register 10-18: ipr3: peripheral interrupt priority register 3 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 tmr5gip lcdip rc2ip tx2ip ctmuip ccp2ip ccp1ip rtccip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr5gip: tmr5 gate interrupt priority bit 1 =high priority 0 = low priority bit 6 lcdip: lcd ready interrupt priority bit 1 =high priority 0 = low priority bit 5 rc2ip: eusart2 receive priority flag bit 1 =high priority 0 = low priority bit 4 tx2ip: eusart2 transmit interrupt priority bit 1 =high priority 0 = low priority bit 3 ctmuip: ctmu interrupt priority bit 1 =high priority 0 = low priority bit 2 ccp2ip: ccp2 interrupt priority bit 1 =high priority 0 = low priority bit 1 ccp1ip: eccp1 interrupt priority bit 1 =high priority 0 = low priority bit 0 rtccip: rtcc interrupt priority bit 1 =high priority 0 = low priority
? 2012 microchip technology inc. ds30575a-page 189 pic18f97j94 family register 10-19: ipr4: peripheral interrupt priority register 4 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ccp10ip ccp9ip ccp8ip ccp7ip ccp6ip ccp5ip ccp4ip eccp3ip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ccp10ip: ccp10 interrupt priority bit 1 = high priority 0 = low priority bit 6 ccp9ip: ccp9 interrupt priority bit 1 = high priority 0 = low priority bit 5 ccp8ip: ccp8 interrupt priority bit 1 = high priority 0 = low priority bit 4 ccp7ip: ccp7 interrupt priority bit 1 = high priority 0 = low priority bit 3 ccp6ip: ccp6 interrupt priority bit 1 = high priority 0 = low priority bit 2 ccp5ip: ccp5 interrupt priority bit 1 = high priority 0 = low priority bit 1 ccp4ip: ccp4 interrupt priority bit 1 = high priority 0 = low priority bit 0 eccp3ip: eccp3 interrupt priority bits 1 = high priority 0 = low priority
pic18f97j94 family ds30575a-page 190 ? 2012 microchip technology inc. register 10-20: ipr5: peripheral interrupt priority register 5 u-0 r/w-1 r/w-1 r/w-1 u-0 r/w-1 r/w-1 r/w-1 ? actorsip actlockip tmr8ip ? tmr6ip tmr5ip tmr4ip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 actorsip: active clock tuning out-of-range interrupt priority bit 1 = high priority 0 = low priority bit 5 actlockip: active clock tuning lock interrupt priority bit 1 = high priority 0 = low priority bit 4 tmr8ip: tmr8 to pr8 match interrupt priority bit 1 = high priority 0 = low priority bit 3 unimplemented: read as ? 0 ? bit 2 tmr6ip: tmr6 to pr6 match interrupt priority bit 1 = high priority 0 = low priority bit 1 tmr5ip: tmr5 overflow interrupt priority bit 1 = high priority 0 = low priority bit 0 tmr4ip: tmr4 to pr4 match interrupt priority bit 1 = high priority 0 = low priority
? 2012 microchip technology inc. ds30575a-page 191 pic18f97j94 family register 10-21: ipr6: peripheral interrupt priority register 6 r/w-1 r/w-1 r/w-1 r/w-1 u-o r/w-1 r/w-1 r/w-1 rc4ip tx4ip rc3ip tx3ip ? cmp3ip cmp2ip cmp1ip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rcp4ip: eusart4 receive interrupt priority bit 1 = high priority 0 = low priority bit 6 tx4ip: eusart4 transmit interrupt priority bit 1 = high priority 0 = low priority bit 5 rc3ip: eusart3 receive interrupt priority bit 1 = high priority 0 = low priority bit 4 tx3ip: eusart3 transmit interrupt priority bit 1 = high priority 0 = low priority bit 3 unimplemented: read as ? 0 ? bit 2 cmp3ip: cmp3 interrupt priority bit 1 = high priority 0 = low priority bit 1 cmp2ip: cmp2 interrupt priority bit 1 = high priority 0 = low priority bit 0 cmp1ip: cmp1 interrupt priority bit 1 = high priority 0 = low priority
pic18f97j94 family ds30575a-page 192 ? 2012 microchip technology inc. 10.8 rcon register the rcon register contains bits used to determine the cause of the last reset or wake-up from idle or sleep modes. rcon also contains the bit that enables interrupt priorities (ipen). register 10-22: rcon: reset control register r/w-0 u-0 r/w-1 r/w-1 r-1 r-1 r/w-0 r/w-0 ipen ?cm ri to pd por bor bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ipen: interrupt priority enable bit 1 = enables priority levels on interrupts 0 = disables priority levels on interrupts (pic16cxxx compatibility mode) bit 6 unimplemented: read as ? 0 ? bit 5 cm : configuration mismatch flag bit 1 = a configuration mismatch reset has not occurred 0 = a configuration mismatch reset has occurred (must be subsequently set in software) bit 4 ri : reset instruction flag bit for details of bit operation, see register 5-1 . bit 3 to : watchdog timer time-out flag bit for details of bit operation, see register 5-1 . bit 2 pd : power-down detection flag bit for details of bit operation, see register 5-1 . bit 1 por : power-on reset status bit for details of bit operation, see register 5-1 . bit 0 bor : brown-out reset status bit for details of bit operation, see register 5-1 .
? 2012 microchip technology inc. ds30575a-page 193 pic18f97j94 family 10.9 intx pin interrupts external interrupts on the rb0/int0, rb1/int1, rb2/int2 and rb3/int3 pins are edge-triggered. if the corresponding intedgx bit in the intcon2 register is set (= 1 ), the interrupt is triggered by a rising edge. if that bit is clear, the trigger is on the falling edge. when a valid edge appears on the rbx/intx pin, the corresponding flag bit, intxif, is set. this interrupt can be disabled by clearing the corresponding enable bit, intxie. before re-enabling the interrupt, the flag bit (intxif) must be cleared in software in the interrupt service routine. all external interrupts (int0, int1, int2 and int3) can wake-up the processor from the power-managed modes if bit, intxie, was set prior to going into the power-managed modes. if the global interrupt enable bit (gie) is set, the processor will branch to the interrupt vector following wake-up. the interrupt priority for int1, int2 and int3 is determined by the value contained in the interrupt priority bits, int1ip (intcon3<6>), int2ip (intcon3<7>) and int3ip (intcon2<1>). there is no priority bit associated with int0. it is always a high-priority interrupt source. 10.10 tmr0 interrupt in 8-bit mode (the default), an overflow in the tmr0 register (ffh ? 00h) will set flag bit, tmr0if. in 16-bit mode, an overflow in the tmr0h:tmr0l register pair (ffffh ? 0000h) will set tmr0if. the interrupt can be enabled/disabled by setting/clearing enable bit, tmr0ie (intcon<5>). interrupt priority for timer0 is determined by the value contained in the inter- rupt priority bit, tmr0ip (intcon2<2>). for further details on the timer0 module, see section 14.0 ?timer0 module? . 10.11 edge-selectable interrupt-on-change interrupt-on-change pins are selected via the pps register settings and have the option of generating an interrupt on positive or negative transitions, or both. positive edge events are enabled by setting the corre- sponding bits in the iocp register, while negative edge events are enabled by setting the corresponding bits in the iocn register. for compatibility with the previous interrupt-on-change feature, both the iocp and iocn bits should be set. the interrupt can be enabled by setting/clearing the iocie (intcon<3>) bit. each individual pin can be disabled by clearing both of the corresponding iocn/iocp bits. a change event (either positive or negative edge) will cause the corresponding iocf flag to be set. interrupt priority for the edge selectable interrupt-on-change is determined by the interrupt priority bit, iocip (intcon2<0>).
pic18f97j94 family ds30575a-page 194 ? 2012 microchip technology inc. register 10-23: iocp: interrupt-on -change positive edge register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 iocp7 iocp6 iocp5 iocp4 iocp3 iocp2 iocp1 iocp0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 iocp<7:0>: interrupt-on-change positive edge enable bits 1 = interrupt-on-change is enabled on the pin for a rising edge; associated status bit and interrupt flag will be set upon detecting an edge 0 = interrupt-on-change is disabled for the associated pin register 10-24: iocn: interrupt-on -change negative edge register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 iocn7 iocn6 iocn5 iocn4 iocn3 iocn2 iocn1 iocn0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 iocn<7:0>: interrupt-on-change negative edge enable bits 1 = interrupt-on-change is enabled on the pin for a falling edge; associated status bit and interrupt flag will be set upon detecting an edge 0 = interrupt-on-change is disabled for the associated pin register 10-25: iocf: inte rrupt-on-change flag register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 iocf7 iocf6 iocf5 iocf4 iocf3 iocf2 iocf1 iocf0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 iocf<7:0>: interrupt-on-change flag bits 1 = an enabled change was detected on the associated pin; this is set when iocp = 1 and a positive edge was detected on the input pin or when iocn = 1 and a negative edge was detected on the input pin (clear in software to clear the iocif bit) 0 = no change was detected or the user cleared the detected change
? 2012 microchip technology inc. ds30575a-page 195 pic18f97j94 family 10.12 context saving during interrupts during interrupts, the return pc address is saved on the stack. additionally, the wreg, status and bsr registers are saved on the fast return stack. if a fast return from interrupt is not used (see section 6.3 ?data memory organization? ), the user may need to save the wreg, status and bsr regis- ters on entry to the interrupt service routine (isr). depending on the user?s application, other registers also may need to be saved. example 10-1 saves and restores the wreg, status and bsr registers during an interrupt service routine. example 10-1: saving status, wreg and bsr registers in ram movwf w_temp ; w_temp is in virtual bank movff status, status_temp ; status_temp located anywhere movff bsr, bsr_temp ; bsr_tmep located anywhere ; ; user isr code ; movff bsr_temp, bsr ; restore bsr movf w_temp, w ; restore wreg movff status_temp, status ; restore status
pic18f97j94 family ds30575a-page 196 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 197 pic18f97j94 family 11.0 i/o ports depending on the device selected and features enabled, there are up to eleven ports available. some pins of the i/o ports are multiplexed with an alternate function from the peripheral features on the device. in general, when a peripheral is enabled, that pin may not be used as a general purpose i/o pin. each port has three memory mapped registers for its operation: ? tris register (data direction register) ? port register (reads the levels on the pins of the device) ? lat register (output latch register) reading the port register reads the current status of the pins, whereas writing to the port register, writes to the output latch (lat) register. setting a tris bit (= 1 ) makes the corresponding port pin an input (putting the corresponding output driver in a high-impedance mode). clearing a tris bit (= 0 ) makes the corresponding port pin an output (i.e., driving the contents of the corresponding lat bit on the selected pin). the output latch (lat register) is useful for read-modify-write operations on the value that the i/o pins are driving. read-modify-write operations on the lat register read and write the latched output value for the port register. a simplified model of a generic i/o port, without the interfaces to other peripherals, is shown in figure 11-1 . figure 11-1: generic i/o port operation 11.1 i/o port pin capabilities when developing an application, the capabilities of the port pins must be considered. all of the digital ports are 3.6v input tolerant. 11.1.1 output pin drive when used as digital i/o, the output pin drive strengths vary, according to the pins? grouping, to meet the needs for a variety of applications. in general, there are two classes of output pins in terms of drive capability: ? outputs designed to drive higher current loads, such as leds: -portb -portc ? outputs with lower drive levels, but capable of driving normal digital circuit loads with a high input impedance. able to drive leds, but only those with smaller current requirements: - porta - portd - porte - portf -portg - porth ( 1 ) -portj ( 1 ) -portk ( 2 ) -portl ( 2 ) 11.1.2 pull-up configuration nine of the i/o ports (all ports except porta and portc) implement configurable weak pull-ups on all pins. these are internal pull-ups that allow floating digital input signals to be pulled to a consistent level without the use of external resistors. pull-ups for portb are enabled by clearing the rbpu bit (intcon2<7>). portb pull-ups are individually selectable through the wpub register. pull-ups for portd, porte, portf, portg, porth, portj, portk and portl are enabled through their corresponding enable bits in the padcfg register, but are not pin-selectable. data bus wr lat wr tris rd port data latch tris latch rd tris input buffer i/o pin q d ckx q d ckx qd en rd lat or port note 1: these ports are not available on 80-pin devices. 2: these ports are not available on 80-pin or 100-pin devices.
pic18f97j94 family ds30575a-page 198 ? 2012 microchip technology inc. register 11-1: padcfg1: pad configuration register 1 ( 1 ) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 rdpu repu rfpu rgpu rhpu rjpu rkpu rlpu bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rdpu: portd pull-up enable bit 1 = portd pull-ups are enabled for any input pad 0 = all portd pull-ups are disabled bit 6 repu: porte pull-up enable bit 1 = porte pull-ups are enabled for any input pad 0 = all porte pull-ups are disabled bit 5 rfpu: portf pull-up enable bit 1 = portf pull-ups are enabled for any input pad 0 = all portf pull-ups are disabled bit 4 rgpu: portg pull-up enable bit 1 = portg pull-ups are enabled for any input pad 0 = all portg pull-ups are disabled bit 3 rhpu: porth pull-up enable bit 1 = porth pull-ups are enabled for any input pad 0 = all porth pull-ups are disabled bit 2 rjpu: portj pull-up enable bit 1 = portj pull-ups are enabled for any input pad 0 = all portj pull-ups are disabled bit 1 rkpu: portk pull-up enable bit 1 = portk pull-ups are enabled for any input pad 0 = all portk pull-ups are disabled bit 0 rlpu: portl pull-up enable bit 1 = portl pull-ups are enabled for any input pad 0 = all portl pull-ups are disabled note 1: if a particular port is not available on a package, the corresponding rnpu register bit will be unimplemented and read back as ? 0 ?.
? 2012 microchip technology inc. ds30575a-page 199 pic18f97j94 family 11.1.3 open-drain outputs the output pins for several peripherals are also equipped with a configurable, open-drain output option. this allows the peripherals to communicate with external digital logic, operating at a higher voltage level, without the use of level translators. the open-drain option is implemented on the eusarts, the msspx modules (in spi mode) and the ccp modules. these modules are assigned to an i/o pin using the pps (peripheral pin select) feature. the open-drain option is enabled by setting the open-drain control bits in the odcon1 and odcon2 registers. when the open-drain option is required, the output pin must also be tied through an external pull-up resistor, provided by the user, to a higher voltage level, up to 5v ( figure 11-2 ). when a digital logic high signal is output, it is pulled up to the higher voltage level. figure 11-2: using the open-drain output (usart shown as example) tx x +5v 3.3v (at logic ? 1 ?) 3.3v v dd 5v pic18f97j94 register 11-2: odcon1: peripheral open-drain control register 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eccp2od eccp1od usart4od usart3od usart2od usart1od ssp2od ssp1od bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 eccp2od: eccp2 open drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 6 eccp1od: eccp1 open drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 5 usart4od: eusart4 open drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 4 usart3od: eusart3 open drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 3 usart2od: eusart2 open drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 2 usart1od: eusart1 open drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 1 ssp2od: open drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 0 ssp1od: spi1 open drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled
pic18f97j94 family ds30575a-page 200 ? 2012 microchip technology inc. 11.1.4 analog and digital ports many of the ports multiplex analog and digital function- ality, providing a lot of flexibility for hardware designers. pic18f97j94 family devices can make any analog pin analog or digital, depending on an application?s needs. the ports? analog/digital functionality is controlled by the registers: ancon1, ancon2 and ancon3. setting these registers makes the corresponding pins analog and clearing the registers makes the ports digital. for details on these registers, see section 22.0 ?12-bit a/d converter with threshold scan? register 11-3: odcon2: peripheral open-drain control register 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ccp10od ccp9od ccp8od ccp7od ccp6od ccp5od ccp4od eccp3od bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ccp10od: ccp10 open-drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 6 ccp9od: ccp9 open-drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 5 ccp8od: ccp8 open-drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 4 ccp7od: ccp7 open-drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 3 ccp6od: ccp6 open-drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 2 ccp5od: ccp5 open-drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 1 ccp4od: ccp4 open-drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled bit 0 eccp3od: eccp3 open-drain output enable bit 1 = open-drain capability is enabled 0 = open-drain capability is disabled
? 2012 microchip technology inc. ds30575a-page 201 pic18f97j94 family 11.2 porta, lata and trisa registers porta is an 8-bit wide, bidirectional port. the corre- sponding data direction and output latch registers are trisa and lata. all porta pins have schmitt trigger input levels and full cmos output drivers. ra<5:0> are multiplexed with analog inputs for the a/d converter. the operation of the analog inputs as a/d converter inputs is selected by clearing or setting the anselx control bits in the ancon1 register. the corresponding trisa bits control the direction of these pins, even when they are being used as analog inputs. the user must ensure the bits in the trisa register are maintained set when using them as analog inputs. osc2/clko/ra6 and osc1/clki/ra7 normally serve as the external circuit connections for the exter- nal (primary) oscillator circuit (hs oscillator modes), or the external clock input and output (ec oscillator modes). in these cases, ra6 and ra7 are not available as digital i/o, and their corresponding tris and lat bits are read as ? 0 ?. when the device is configured to use either the frc or lprc internal oscillators as the default oscillator mode, ra6 and ra7 are automatically configured as digital i/o; the oscillator and clock in/clock out functions are disabled. example 11-1: initializing porta note: ra<5:0> are configured as analog inputs on any reset and are read as ? 0 ?. clrf porta ; initialize porta by ; clearing output latches clrf lata ; alternate method to ; clear output data latches banksel ancon1 ; select bank with ancon1 register movlw 00h ; configure a/d movwf ancon1 ; for digital inputs banksel trisa ; select bank with trisa register movlw 0bfh ; value used to initialize ; data direction movwf trisa ; set ra<7, 5:0> as inputs, ; ra<6> as output table 11-1: porta functions pin name function tris setting i/o i/o type description ra0/an0/an1-/rp0/ seg19 ra0 0 o dig lata<0> data output; not affected by analog input. 1 i st porta<0> data input; disabled when analog input is enabled. an0 1 i ana a/d input channel 0. default input configuration on por; does not affect digital output. an1- 1 i ana quasi-differential a/d negative input channel. rp0 x x dig reconfigurable pin 0 for pps-lite; tris must be set to match input/output of the module. seg19 0 o ana lcd segment 19 output; disables all other pin functions. ra1/an1/rp1/seg18 ra1 0 o dig lata<1> data output; not affected by analog input. 1 i st porta<1> data input; disabled when analog input is enabled. an1 1 i ana a/d input channel 1. default input configuration on por; does not affect digital output. rp1 x x dig reconfigurable pin 1 for pps-lite; tris must be set to match input/output of module. seg18 0 o ana lcd segment 18 output; disables all other pin functions. ra2/an2/v ref -/rp2/ seg21 ra2 0 o dig lata<2> data output; not affected by analog input. 1 i st porta<2> data input; disabled when analog input enabled. an2 1 i ana a/d input channel 2. default input configuration on por; does not affect digital output. v ref - 1 i ana a/d and comparator low reference voltage input. rp2 x x dig reconfigurable pin 2 for pps-lite; tris must be set to match input/output of module. seg21 0 o ana lcd segment 21 output; disables all other pin functions. legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
pic18f97j94 family ds30575a-page 202 ? 2012 microchip technology inc. ra3/an3/v ref +/rp3 ra3 0 o dig lata<3> data output; not affected by analog input. 1 i st porta<3> data input; disabled when analog input is enabled. an3 1 i ana a/d input channel 3. default input configuration on por; does not affect digital output. v ref + 1 i ana a/d and comparator high reference voltage input. rp3 x x dig reconfigurable pin 3 for pps-lite; tris must be set to match input/output of module. ra4/an6/rp4/seg14 ra4 0 o dig lata<4> data output; not affected by analog input. 1 i st porta<4> data input; disabled when analog input is enabled. an6 1 i ana a/d input channel 6. default input configuration on por; does not affect digital output. rp4 x x dig reconfigurable pin 4 for pps-lite; tris must be set to match input/output of module. seg14 0 o ana lcd segment 14 output; disables all other pin functions. ra5/an4/rp5/lvdin/ c1ina/c2ina/c3ina/ seg15 ra5 0 o dig lata<5> data output; not affected by analog input. 1 i st porta<5> data input; disabled when analog input is enabled. an4 1 i ana a/d input channel 4. default input configuration on por; does not affect digital output. rp5 x x dig reconfigurable pin 5 for pps-lite; tris must be set to match input/output of module. lvdin 1 i ana high/low-voltage detect (hlvd) external trip point input. c1ina 1 i ana comparator 1 input a. c2ina 1 i ana comparator 2 input a. c3ina 1 i ana comparator 3 input a. seg15 0 o ana lcd segment 15 output; disables all other pin functions. ra6/rp6/clko/osc2 ra6 0 o dig lata<6> data output; disabled when osc2 configuration bit is set. 1 i st porta<6> data input; disabled when osc2 configuration bit is set. rp6 x x dig reconfigurable pin 6 for pps-lite; tris must be set to match input/output of module. clko x o dig system cycle clock output (f osc /4, ec and internal oscillator modes). osc2 x o ana main oscillator feedback output connection (hs, ms and lp modes). ra7/rp10/clki/osc1 ra7 0 o dig lata<7> data output; disabled when osc2 configuration bit is set. 1 i st porta<7> data input; disabled when osc2 configuration bit is set. rp10 x x dig reconfigurable pin 10 for pps-lite; tris must be set to match input/output of module. clki x o dig main external clock source input (ec modes). osc1 x o ana main oscillator input connection (hs, ms and lp modes). table 11-1: porta functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
? 2012 microchip technology inc. ds30575a-page 203 pic18f97j94 family 11.3 portb, latb and trisb registers portb is an eight-bit wide, bidirectional port. the corresponding data direction and output latch registers are trisb and latb. all pins on portb are digital only. example 11-2: initializing portb each of the portb pins has a weak internal pull-up. a single control bit can turn on all the pull-ups. this is performed by clearing bit, r bpu (intcon2<7>), and setting the associated wpub bit. the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on a power-on reset. the rb<3:2> pins are multiplexed as ctmu edge inputs. clrf portb ; initialize portb by ; clearing output ; data latches clrf latb ; alternate method ; to clear output ; data latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisb ; set rb<3:0> as inputs ; rb<5:4> as outputs ; rb<7:6> as inputs table 11-2: portb functions pin name function tris setting i/o i/o type description rb0/int0/cted13/ rp8/v lcap 1 rb0 0 o dig latb<0> data output. 1 i st portb<0> data input. int0 1 i st external interrupt 0 input. cted13 1 i st ctmu edge 13 input. rp8 x x dig reconfigurable pin 8 for pps-lite; tris must be set to match input/output of module. v lcap 1 x x ana external capacitor connection for lcd module. rb1/rp9/v lcap 2rb1 0 o dig latb<1> data output. 1 i st portb<1> data input. rp9 x x dig reconfigurable pin 9 for pps-lite; tris must be set to match input/output of module. v lcap 2 x x ana external capacitor connection for lcd module. rb2/cted1/rp14/ seg9 rb2 0 o dig latb<2> data output. 1 i st portb<2> data input. cted1 1 i st ctmu edge 1 input. rp14 x x dig reconfigurable pin 14 for pps-lite; tris must be set to match input/output of module. seg9 0 o ana lcd segment 9 output; disabl es all other pin functions. rb3/cted2/rp7/ seg10 rb3 0 o dig latb<3> data output. 1 i st portb<3> data input. cted2 1 i st ctmu edge 2 input. rp7 x x dig reconfigurable pin 7 for pps-lite; tris must be set to match input/output of module. seg10 0 o ana lcd segment 10 output; disables all other pin functions. legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
pic18f97j94 family ds30575a-page 204 ? 2012 microchip technology inc. rb4/cted3/rp12/ seg11 rb4 0 o dig latb<4> data output. 1 i st portb<4> data input. cted3 1 i st ctmu edge 3 input. rp12 x x dig reconfigurable pin 12 for pps-lite; tris must be set to match input/output of module. seg11 0 o ana lcd segment 11 output; disables all other pin functions. rb5/cted4/rp13/ seg8 rb5 0 o dig latb<5> data output. 1 i st portb<5> data input. cted4 1 i st ctmu edge 4 input. rp13 x x dig reconfigurable pin 13 for pps-lite; tris must be set to match input/output of module. seg8 0 o ana lcd segment 8 output; disabl es all other pin functions. rb6/cted5/pgc rb6 0 o dig latb<6> data output. 1 i st portb<6> data input. cted5 1 i st ctmu edge 5 input. pgc x i st serial execution (icsp?) clock input for icsp and icd operations. rb7/cted6/pgd rb7 0 o dig latb<7> data output. 1 i st portb<7> data input. cted6 1 i st ctmu edge 6 input. pgd x i/o st/dig serial execution (icsp?) data input/output for icsp and icd operations. table 11-2: portb functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
? 2012 microchip technology inc. ds30575a-page 205 pic18f97j94 family 11.4 portc, latc and trisc registers portc is an eight-bit wide, bidirectional port. the corresponding data direction and output latch registers are trisc and latc. only portc pins, rc2 through rc7, are digital only pins. the pins have schmitt trigger input buffers. when enabling peripheral functions, use care in defin- ing tris bits for each portc pin. some peripherals can override the tris bit to make a pin an output or input. consult the corresponding peripheral section for the correct tris bit settings. the contents of the trisc register are affected by peripheral overrides. reading trisc always returns the current contents, even though a peripheral device may be overriding one or more of the pins. example 11-3: initializing portc note: these pins are configured as digital inputs on any device reset. clrf portc ; initialize portc by ; clearing output ; data latches clrf latc ; alternate method ; to clear output ; data latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisc ; set rc<3:0> as inputs ; rc<5:4> as outputs ; rc<7:6> as inputs table 11-3: portc functions pin name function tris setting i/o i/o type description rc0/ pwrlclk/ sclki/sosco rc0 0 o dig latc<0> data output. 1 i st portc<0> data input. pwrlclk 1 i st optional rtcc input from power line clock (50 or 60 hz). sclki x i st digital sosc input. sosco x o ana secondary oscillator (sosc) feedback output connection. rc1/sosci rc1 0 o dig latc<1> data output. 1 i st portc<1> data input. sosci x i ana secondary oscillator (sosc) input connection. rc2/cted7/ rp11/an9/ seg13 rc2 0 o dig latc<2> data output; not affected by analog input. 1 i st portc<2> data input; disabled when analog input is enabled. cted7 1 i st ctmu edge 7 input. rp11 x x dig reconfigurable pin 11 for pps-lite; tris must be set to match input/output of module. an9 1 i ana a/d input channel 9. default input configuration on por; does not affect digital output. seg13 0 o ana lcd segment 13 output; disables all other pin functions. rc3/cted8/ rp15/scl1/ seg17 rc3 0 o dig latc<3> data output. 1 i st portc<3> data input. cted8 1 i st ctmu edge 8 input. rp15 x x dig reconfigurable pin 15 for pps-lite; tris must be set to match input/output of module. scl1 x i/o i2c synchronous serial clock input/output for i 2 c? mode. seg17 0 o ana lcd segment 17 output; disables all other pin functions rc4/cted9/ rp17/sda1/ seg16 rc4 0 o dig latc<4> data output. 1 i st portc<4> data input. cted9 1 i st ctmu edge 9 input. rp17 x x dig reconfigurable pin 17 for pps-lite; tris must be set to match input/output of module. sda1 x i/o i2c i 2 c? mode data i/o seg16 0 o ana lcd segment 16 output; disables all other pin functions. legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, i2c = i 2 c?/smbus, x = don?t care (tris bit does not affect port direction or is overridden for this option).
pic18f97j94 family ds30575a-page 206 ? 2012 microchip technology inc. rc5/cted10/ rp16/seg12 rc5 0 o dig latc<5> data output. 1 i st portc<5> data input. cted10 1 i st ctmu edge 10 input. rp16 x x dig reconfigurable pin 16 for pps-lite; tris must be set to match input/output of module. seg12 0 o ana lcd segment 12 output; disables all other pin functions. rc6/cted11/ uoe /rp18/ seg27 rc6 0 o dig latc<6> data output. 1 i st portc<6> data input. cted11 1 i st ctmu edge 11 input. uoe 0 o dig usb output enable contro l (for external transceiver). rp18 x x dig reconfigurable pin 18 for pps-lite; tris must be set to match input/output of module. seg27 0 o ana lcd segment 27 output; disables all other pin functions. rc7/cted12/ rp19/seg22 rc7 0 o dig latc<7> data output. 1 i st portc<7> data input. cted12 1 i st ctmu edge 12 input. rp19 x x dig reconfigurable pin 19 for pps-lite; tris must be set to match input/output of module. seg22 0 o ana lcd segment 22 output; disables all other pin functions. table 11-3: portc functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, i2c = i 2 c?/smbus, x = don?t care (tris bit does not affect port direction or is overridden for this option).
? 2012 microchip technology inc. ds30575a-page 207 pic18f97j94 family 11.5 portd, latd and trisd registers portd is an 8-bit wide, bidirectional port. the corresponding data direction and output latch registers are trisd and latd. all pins on portd are implemented with schmitt trigger input buffers. each pin is individually configurable as an input or output. each of the portd pins has a weak internal pull-up. a single control bit can turn off all the pull-ups. this is performed by setting bit, rdpu (padcfg<7>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on all device resets. on 80-pin and 100-pin devices, portd is multiplexed with the system bus as part of the external memory interface. i/o port and other functions are only available when the interface is disabled by setting the ebdis bit (memcon<7>). when the interface is enabled, portd is the low-order byte of the multiplexed address/data bus (ad<7:0>). the trisd bits are also overridden. portd can also be configured as an 8-bit wide micro- processor port (parallel slave port) by setting control bit, pspmode (pspcon<4>). in this mode, the input buffers are ttl. for additional information, see section 11.13 ?parallel slave port? . portd also has i 2 c functionality on rd5 and rd6. example 11-4: initializing portd note: these pins are configured as digital inputs on any device reset. clrf portd ; initialize portd by ; clearing output ; data latches clrf latd ; alternate method ; to clear output ; data latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisd ; set rd<3:0> as inputs ; rd<5:4> as outputs ; rd<7:6> as inputs table 11-4: portd functions pin name function tris setting i/o i/o type description rd0/psp0/ rp20/seg0/ad0 rd0 0 o dig latd<0> data output. 1 i st portd<0> data input. psp0 x i/o st/dig parallel slave port data bus bit 0. rp20 x x dig reconfigurable pin 20 for pps-lite; tris must be set to match input/output of module. seg0 0 o ana lcd segment 0 output; disables all other pin functions. ad0 x i/o st/dig external memory bus address line 0. rd1/psp1/ rp21/seg1/ad1 rd1 0 o dig latd<1> data output. 1 i st portd<1> data input. psp1 x i/o st/dig parallel slave port data bus bit 1. rp21 x x dig reconfigurable pin 21 for pps-lite; tris must be set to match input/output of module. seg1 0 o ana lcd segment 1 output; disables all other pin functions. ad1 x i/o st/dig external memory bus address line 1. rd2/psp2/ rp22/seg2/ad2 rd2 0 o dig latd<2> data output. 1 i st portd<2> data input. psp2 x i/o st/dig parallel slave port data bus bit 2. rp22 x x dig reconfigurable pin 22 for pps-lite; tris must be set to match input/output of module. seg2 0 o ana lcd segment 2 output; disables all other pin functions. ad2 x i/o st/dig external memory bus address line 2. legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, i2c = i 2 c?/smbus, x = don?t care (tris bit does not affect port direction or is overridden for this option).
pic18f97j94 family ds30575a-page 208 ? 2012 microchip technology inc. rd3/psp3/ rp23/seg3/ad3 rd3 0 o dig latd<3> data output. 1 i st portd<3> data input. psp3 x i/o st/dig parallel slave port data bus bit 3. rp23 x x dig reconfigurable pin 23 for pps-lite; tris must be set to match input/output of module. seg3 0 o ana lcd segment 3 output; disables all other pin functions. ad3 x i/o st/dig external memory bus address line 3. rd4/psp4/ rp24/seg4/ad4 rd4 0 o dig latd<4> data output. 1 i st portd<4> data input. psp4 x i/o st/dig parallel slave port data bus bit 4. rp24 xx dig reconfigurable pin 24 for pps-lite; tris must be set to match input/output of module. seg4 0 o ana lcd segment 4 output; disables all other pin functions. ad4 x i/o st/dig external memory bus address line 4. rd5/psp5/ rp25/sda2/ seg5/ad5 rd5 0 o dig latd<5> data output. 1 i st portd<5> data input. psp5 x i/o st/dig parallel slave port data bus bit 5. rp25 x x dig reconfigurable pin 25 for pps-lite; tris must be set to match input/output of module. sda2 x i/o st/dig i 2 c mode data i/o. seg5 0 o ana lcd segment 5 output; disables all other pin functions. ad5 x i/o st/dig external memory bus address line 5. rd6/psp6/ rp26/scl2/ seg6/ad6 rd6 0 o dig latd<6> data output. 1 i st portd<6> data input. psp6 x i/o st/dig parallel slave port data bus bit 6. rp26 x x dig reconfigurable pin 26 for pps-lite; tris must be set to match input/output of module. scl2 x i/o i2c synchronous serial clock input/output for i 2 c? mode. seg6 0 o ana lcd segment 6 output; disables all other pin functions. ad6 x i/o st/dig external memory bus address line 6. rd7/psp7/ rp27/refo2/ seg7/ad7 rd7 0 o dig latd<7> data output. 1 i st portd<7> data input. psp7 x i/o st/dig parallel slave port data bus bit 7. rp27 x x dig reconfigurable pin 27 for pps-lite; tris must be set to match input/output of module. refo2 0 o dig reference clock 2 output. seg7 0 o ana lcd segment 7 output; disables all other pin functions. ad7 x i/o st/dig external memory bus address line 7. table 11-4: portd functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, i2c = i 2 c?/smbus, x = don?t care (tris bit does not affect port direction or is overridden for this option).
? 2012 microchip technology inc. ds30575a-page 209 pic18f97j94 family 11.6 porte, late and trise registers porte is an eight-bit wide, bidirectional port. the corresponding data direction and output latch registers are trise and late. all pins on porte are implemented with schmitt trigger input buffers. each pin is individually configurable as an input or output. each of the porte pins has a weak internal pull-up. a single control bit can turn off all the pull-ups. this is performed by setting bit, repu (padcfg<6>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on any device reset. for devices operating in microcontroller mode, the re7 pin can be configured as the alternate peripheral pin for the eccp2 module and enhanced pwm output 2a. porte is also multiplexed with the parallel slave port address lines. re2, re1 and re0 are multiplexed with the control signals, cs , wr and rd . re3 can also be configured as the reference clock output (refo) from the system clock. for further details, see section 3.4 ?reference clock output control module? . example 11-5: initializing porte note: these pins are configured as digital inputs on any device reset. clrf porte ; initialize porte by ; clearing output ; data latches clrf late ; alternate method ; to clear output ; data latches movlw 03h ; value used to ; initialize data ; direction movwf trise ; set re<1:0> as inputs ; re<7:2> as outputs table 11-5: porte functions pin name function tris setting i/o i/o type description re0//rd /rp28/ lcdbias1/ad8 re0 0 o dig late<0> data output. 1 i st porte<0> data input. rd 1 i st parallel slave port (psp) read (rd ) signal. rp28 x x dig reconfigurable pin 28 for pps-lite; tris must be set to match input/output of module. lcdbias1 x i ana lcd module bias voltage input 1. ad8 x i/o st/dig external memory bus address line 8. re1//wr /rp29/ lcdbias2/ad9 re1 0 o dig late<1> data output. 1 i st porte<1> data input. wr 1 i st parallel slave port (psp) write (wr ) signal. rp29 x x dig reconfigurable pin 29 for pps-lite; tris must be set to match input/output of module. lcdbias2 x i ana lcd module bias voltage input 2. ad9 x i/o st/dig external memory bus address line 9. re2/cs /rp30/ lcdbias3/ad10 re2 0 o dig late<2> data output. 1 i st porte<2> data input. cs 1 i st parallel slave port (psp) chip select (cs ) signal. rp30 x x dig reconfigurable pin 30 for pps-lite; tris must be set to match input/output of module. lcdbias3 x i ana lcd module bias voltage input 3. ad10 x i/o st/dig external memory bus address line 10. legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
pic18f97j94 family ds30575a-page 210 ? 2012 microchip technology inc. re3/refo1/ rp33/com0/ ad11 re3 0 o dig late<3> data output. 1 i st porte<3> data input. refo1 0 o dig reference clock output 1. rp33 x x dig reconfigurable pin 33 for pps-lite; tris must be set to match input/output of module. com0 x o ana lcd common 0 output; disables all other outputs. ad11 x i/o st/dig external memory bus address line 11. re4/rp32/ com1/ad12 re4 0 o dig late<4> data output. 1 i st porte<4> data input. rp32 x x dig reconfigurable pin 32 for pps-lite; tris must be set to match input/output of module. com1 x o ana lcd common 1 output; disables all other outputs. ad12 x i/o st/dig external memory bus address line 12. re5/rp37/ com2/ad13 re5 0 o dig late<5> data output. 1 i st porte<5> data input. rp37 x x dig reconfigurable pin 37 for pps-lite; tris must be set to match input/output of module. com2 x o ana lcd common 2 output; disables all other outputs. ad13 x i/o st/dig external memory bus address line 13. re6/rp34/ com3/ad14 re6 0 o dig late<6> data output. 1 i st porte<6> data input. rp34 x x dig reconfigurable pin 34 for pps-lite; tris must be set to match input/output of module. com3 x o ana lcd common 3 output; disables all other outputs. ad14 x i/o st/dig external memory bus address line 14. re7/rp31/ lcdbias0/ ad15 re7 0 o dig late<7> data output. 1 i st porte<7> data input. rp31 x x dig reconfigurable pin 31 for pps-lite; tris must be set to match input/output of module. lcdbias0 x i ana lcd module bias voltage input 0. ad15 x i/o st/dig external memory bus address line 15. table 11-5: porte functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
? 2012 microchip technology inc. ds30575a-page 211 pic18f97j94 family 11.7 portf, latf and trisf registers portf is a 6-bit wide, bidirectional port. the corresponding data direction and output latch registers are trisf and latf. all pins on portf are implemented with schmitt trigger input buffers. each pin is individually configurable as an input or output. pins, rf2 through rf6, may be used as comparator inputs or outputs by setting the appropriate bits in the cmcon register. to use rf<7:2> as digital inputs, it is also necessary to turn off the comparators. example 11-6: initializing portf note 1: on device resets, pins, rf<7:2>, are configured as analog inputs and are read as ? 0 ?. 2: to configure portf as a digital i/o, turn off the comparators and clear ancon1 and ancon2 to digital. clrf portf ; initialize portf by ; clearing output ; data latches clrf latf ; alternate method ; to clear output ; data latches banksel ancon1 ; select bank with ancon1 register movlw 1fh ; make an6, an7 and an5 digital movwf ancon1 ; movlw 0fh ; make an8, an9, an10 and an11 digital movwf ancon ; set portf as digital i/o banksel trisf ; select bank with trisf register movlw 0ceh ; value used to ; initialize data ; direction movwf trisf ; set rf3:rf2 as inputs ; rf5:rf4 as outputs ; rf7:rf6 as inputs table 11-6: portf functions pin name function tris setting i/o i/o type description rf0 ? ? ? ? portf<0> is not implemented. rf1 ? ? ? ? portf<1> is not implemented. rf2/rp36/c2inb/ ctmui/seg20/ an7 rf2 0 o dig latf<2> data output. 1 i st portf<2> data input. rp36 x x dig reconfigurable pin 36 for pps-lite; tris must be set to match input/output of module. c2inb 1 i ana comparator 2 input b. ctmui 1 i ana ctmu comparator input. seg20 0 o ana lcd segment 20 output; disables all other pin functions. an7 1 i ana a/d input channel 7. default input configuration on por; does not affect digital output. rf3/rp41/d- rf3 0 o dig latf<3> data output. 1 i st portf<3> data input. rp41 x x dig reconfigurable pin 41 for pps-lite; tris must be set to match input/output of module. d- x i xcvr usb bus minus line output. x o xcvr usb bus minus line input. rf4/rp45/d+ rf4 0 o dig latf<4> data output. 1 i st portf<4> data input. rp45 x x dig reconfigurable pin 45 for pps-lite. d+ x i xcvr usb bus plus line input. x o xcvr usb bus plus line output. legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, xcvr = usb transceiver, x = don?t care (tris bit does not affect port direction or is overridden for this option).
pic18f97j94 family ds30575a-page 212 ? 2012 microchip technology inc. rf5/rp35/c1inb/ an10/cv ref / seg23 rf5 0 o dig latf<5> data output. 1 i st portf<5> data input. rp35 x x dig reconfigurable pin 35 for pps-lite; tris must be set to match input/output of module. c1inb 1 i ana comparator 1 input b. an10 1 i ana a/d input channel 10. default input configuration on por; does not affect digital output. cv ref 0 o ana comparator reference voltage output. seg23 0 o ana lcd segment 23 output; disables all other pin functions. rf6/rp40/c1ina/ an11/seg24 rf6 0 o dig latf<6> data output. 1 i st portf<6> data input. rp40 x x dig reconfigurable pin 40 for pps-lite; tris must be set to match input/output of module. c1ina 1 i ana comparator 1 input a. an11 1 i ana a/d input channel 11. default input configuration on por; does not affect digital output. seg24 0 o ana lcd segment 24 output; disables all other pin functions. rf7/rp38/an5/ seg25 rf7 0 o dig latf<7> data output. 1 i st portf<7> data input. rp38 x x dig reconfigurable pin 38 for pps-lite; tris must be set to match input/output of module. an5 1 i ana a/d input channel 5. default input configuration on por; does not affect digital output. seg25 0 o ana lcd segment 25 output; disables all other pin functions. table 11-6: portf functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, xcvr = usb transceiver, x = don?t care (tris bit does not affect port direction or is overridden for this option).
? 2012 microchip technology inc. ds30575a-page 213 pic18f97j94 family 11.8 portg, latg and trisg registers portg width varies depending on pin count. for 64- and 80-pin devices, portg is a 6-bit wide, bidirec- tional port. for 100-pin devices, portg is an 8-bit wide bidirectional port. the corresponding data direction and output latch registers are trisg and latg. portg is multiplexed with the eusart, and ccp, eccp, analog, comparator, rtcc and timer input functions ( table 11-7 ). when operating as i/o, all portg pins have schmitt trigger input buffers. the open-drain functionality for the ccpx and eusartx can be configured using odconx. when enabling peripheral functions, care should be taken in defining tris bits for each portg pin. some peripherals override the tris bit to make a pin an output, while other peripherals override the tris bit to make a pin an input. the user should refer to the corresponding peripheral section for the correct tris bit settings. the pin override value is not loaded into the tris register. this allows read-modify-write of the tris register without concern due to peripheral overrides. example 11-7: initializing portg clrf portg ; initialize portg by ; clearing output ; data latches bcf cm1con, con ; disable ; comparator 1 clrf latg ; alternate method ; to clear output ; data latches banksel ancon2 ; select bank with acon2 register movlw 0f0h ; make an16 to an19 ; digital movwf ancon2 banksel trisg ; select bank with trisg register movlw 04h ; value used to ; initialize data ; direction movwf trisg ; set rg1:rg0 as ; outputs ; rg2 as input ; rg4:rg3 as inputs table 11-7: portg functions pin name function tris setting i/o i/o type description rg0/rp46/an8/ seg28/com4 rg0 0 o dig latg<0> data output; not affected by analog input. 1 i st portg<0> data input; disabled when analog input is enabled. rp46 x x dig reconfigurable pin 46 for pps-lite; tris must be set to match input/output of module. an8 1 i ana a/d input channel 8. default input configuration on por; does not affect digital output. seg28 0 o ana lcd segment 28 output; disables all other pin functions. com4 x o ana lcd common 4 output; disables all other outputs. rg1/rp39/ an19/seg29/ com5 rg1 0 o dig latg<1> data output; not affected by analog input. 1 i st portg<1> data input; disabled when analog input is enabled. rp39 x x dig reconfigurable pin 39 for pps-lite; tris must be set to match input/output of module. an19 1 i ana a/d input channel 19. default input configuration on por; does not affect digital output. seg29 0 o ana lcd segment 29 output; disables all other pin functions. com5 x o ana lcd common 5 output; disables all other outputs. rg2/rp42/ c3ina/an18/ seg30/com6 rg2 0 o dig latg<2> data output; not affected by analog input. 1 i st portg<2> data input; disabled when analog input is enabled. rp42 x x dig reconfigurable pin 42 for pps-lite; tris must be set to match input/output of module. c3ina 1 i ana comparator 3 input a. an18 1 i ana a/d input channel 18. default input configuration on por; does not affect digital output. seg30 0 o ana lcd segment 30 output; disables all other pin functions. com6 x o ana lcd common 6 output; disables all other outputs. legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
pic18f97j94 family ds30575a-page 214 ? 2012 microchip technology inc. rg3/rp43/ c3inb/an17/ seg31/com7 rg3 0 o dig latg<3> data output; not affected by analog input. 1 i st portg<3> data input; disabled when analog input is enabled. rp43 x x dig reconfigurable pin 43 for pps-lite; tris must be set to match input/output of module. c3inb 1 i ana comparator 3 input b. an17 1 i ana a/d input channel 17. default input configuration on por; does not affect digital output. seg31 0 o ana lcd segment 31 output; disables all other pin functions. com7 x o ana lcd common 7 output; disables all other outputs. rg4/rtcc/ rp44/c3inc/ an16/seg26 rg4 0 o dig latg<4> data output; not affected by analog input. 1 i st portg<4> data input; disabled when analog input is enabled. rtcc x o dig rtcc output. rp44 x x dig reconfigurable pin 44 for pps-lite; tris must be set to match input/output of module. c3inc 1 i ana comparator 3 input c. an16 1 i ana a/d input channel 16. default input configuration on por; does not affect digital output. seg26 0 o ana lcd segment 26 output; disables all other pin functions. rg6 rg6 0 o dig latg<6> data output. 1 i st portg<6> data input. rg7 rg7 0 o dig latg<7> data output. 1 i st portg<7> data input. table 11-7: portg functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
? 2012 microchip technology inc. ds30575a-page 215 pic18f97j94 family 11.9 porth, lath and trish registers porth is an 8-bit wide, bidirectional i/o port. the corresponding data direction and output latch registers are trish and lath. all pins on porth are implemented with schmitt trigger input buffers. each pin is individually configurable as an input or output. example 11-8: initializing porth note: porth is available only on 80-pin and 100-pin devices. clrf porth ; initialize porth by ; clearing output ; data latches clrf lath ; alternate method ; to clear output ; data latches banksel ancon2 ; select bank with ancon2 register movlw 0fh ; configure porth as movwf ancon2 ; digital i/o movlw 0fh ; configure porth as movwf ancon1 ; digital i/o banksel trish ; select bank with trish register movlw 0cfh ; value used to ; initialize data ; direction movwf trish ; set rh3:rh0 as inputs ; rh5:rh4 as outputs ; rh7:rh6 as inputs table 11-8: porth functions pin name function tris setting i/o i/o type description rh0/an23/ seg47/a16 rh0 0 o dig lath<0> data output; not affected by analog input. 1 i st porth<0> data input. an23 1 i ana a/d input channel 23. default input configuration on por; does not affect digital output. seg47 0 o ana lcd segment 47 output; disables all other pin functions. a16 x o dig external memory bus address<16> output. rh1/an22/ seg46/a17 rh1 0 o dig lath<1> data output; not affected by analog input. 1 i st porth<1> data input. an22 1 i ana a/d input channel 22. default input configuration on por; does not affect digital output. seg46 0 o ana lcd segment 46 output; disables all other pin functions. a17 x o dig external memory bus address<17> output. rh2/an21/ seg45/a18 rh2 0 o dig lath<2> data output; not affected by analog input. 1 i st porth<2> data input. an21 1 i ana a/d input channel 21. default input configuration on por; does not affect digital output. seg45 0 o ana lcd segment 45 output; disables all other pin functions. a18 x o dig external memory bus address<18> output. rh3/an20/ seg44/a19 rh3 0 o dig lath<3> data output; not affected by analog input. 1 i st porth<3> data input. an20 1 i ana a/d input channel 20. default input configuration on por; does not affect digital output. seg44 0 o ana lcd segment 44 output; disables all other pin functions. a19 x o dig external memory bus address<19> output. rh4/c2inc/ an12/seg40 rh4 0 o dig lath<4> data output; not affected by analog input. 1 i st porth<4> data input; disabled when analog input is enabled. c2inc 1 i ana comparator 2 input c. an12 1 i ana a/d input channel 12. default input configuration on por; does not affect digital output. seg40 0 o ana lcd segment 40 output; disables all other pin functions. legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
pic18f97j94 family ds30575a-page 216 ? 2012 microchip technology inc. rh5/c2ind/an 13/seg41 rh5 0 o dig lath<5> data output; not affected by analog input. 1 i st porth<5> data input; disabled when analog input is enabled. c2ind 1 i ana comparator 2 input d. an13 1 i ana a/d input channel 13. default input configuration on por; does not affect digital output. seg41 0 o ana lcd segment 41 output; disables all other pin functions. rh6/c1inc/an 14/seg42 rh6 0 o dig lath<6> data output; not affected by analog input. 1 i st porth<6> data input; disabled when analog input is enabled. c1inc 1 i ana comparator 1 input c. an14 1 i ana a/d input channel 14. default input configuration on por; does not affect digital output. seg42 0 o ana lcd segment 42 output; disables all other pin functions. rh7/an15/se g43 rh7 0 o dig lath<7> data output; not affected by analog input. 1 i st porth<7> data input; disabled when analog input is enabled. an15 1 i ana a/d input channel 15. default input configuration on por; does not affect digital output. seg43 0 o ana lcd segment 43 output; disables all other pin functions. table 11-8: porth functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
? 2012 microchip technology inc. ds30575a-page 217 pic18f97j94 family 11.10 portj, latj and trisj registers portj is an 8-bit wide, bidirectional port. the corresponding data direction and output latch registers are trisj and latj. all pins on portj are implemented with schmitt trigger input buffers. each pin is individually configurable as an input or output. when the external memory interface is enabled, all of the portj pins function as control outputs for the inter- face. this occurs automatically when the interface is enabled by clearing the ebdis control bit (memcon<7>). the trisj bits are also overridden. each of the portj pins has a weak internal pull-up. the pull-ups are provided to keep the inputs at a known state for the external memory interface while powering up. a single control bit can turn off all the pull-ups. this is performed by clearing bit, rjpu (padcfg<2>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on any device reset. example 11-9: initializing portj note: portj is available only on 80-pin and 100-pin devices. note: these pins are configured as digital inputs on any device reset. clrf portj ; initialize portj by ; clearing output latches clrf latj ; alternate method ; to clear output latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisj ; set rj3:rj0 as inputs ; rj5:rj4 as output ; rj7:rj6 as inputs table 11-9: portj functions pin name function tris setting i/o i/o type description rj0/seg32/ ale rj0 0 o dig latj<0> data output. 1 i st portj<0> data input. seg32 0 o ana lcd segment 32 output; disables all other pin functions. ale x o dig external memory bus address latch enable (ale) signal. rj1/seg33/oe rj1 0 o dig latj<1> data output. 1 i st portj<1> data input. seg33 0 o ana lcd segment 33 output; disables all other pin functions. oe x o dig external memory bus address latch enable (oe ) signal. rj2/seg34/ wrl rj2 0 o dig latj<2> data output. 1 i st portj<2> data input. seg34 0 o ana lcd segment 34 output; disables all other pin functions. wrl x o dig external memory bus write low (wrl ) signal. rj3/seg35/ wrh rj3 0 o dig latj<3> data output. 1 i st portj<3> data input. seg35 0 o ana lcd segment 35 output; disables all other pin functions. wrh x o dig external memory bus write high (wrh ) signal. rj4/seg39/ ba0 rj4 0 o dig latj<4> data output. 1 i st portj<4> data input. seg39 0 o ana lcd segment 39 output; disables all other pin functions. ba0 x o dig external memory bus byte access 0 (ba0) signal. rj5/seg38/ce rj5 0 o dig latj<5> data output. 1 i st portj<5> data input. seg38 0 o ana lcd segment 38 output; disables all other pin functions. ce x o dig external memory bus chip enable (ce ) signal. legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
pic18f97j94 family ds30575a-page 218 ? 2012 microchip technology inc. rj6/seg37/lb rj6 0 o dig latj<6> data output. 1 i st portj<6> data input. seg37 0 o ana lcd segment 37 output; disables all other pin functions. lb x o dig external memory bus lower byte (lb ) signal. rj7/seg36/ub rj7 0 o dig latj<7> data output. 1 i st portj<7> data input. seg36 0 o ana lcd segment 36 output; disables all other pin functions. ub x o dig external memory bus upper byte (ub ) signal. table 11-9: portj functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
? 2012 microchip technology inc. ds30575a-page 219 pic18f97j94 family 11.11 portk, latk and trisk registers portk is an 8-bit wide, bidirectional port. the corre- sponding data direction and output latch registers are trisk and latk. all pins on portk are implemented with schmitt trig- ger input buffers. each pin is individually configurable as an input or output. each of the portk pins has a weak internal pull-up. the pull-ups are provided to keep the inputs at a known state for the external memory interface while powering up. a single control bit can turn off all the pull-ups. this is performed by clearing bit, rkpu (padcfg<1>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on any device reset. example 11-10: initializing portk note: portk is available only on 100-pin devices. banksel latk ; select bank with latk register clrf latk ; initialize latk ; by clearing output ; data latches banksel trisk ; select bank with trisk register movlw 0cfh ; value used to ; initialize data ; direction movwf trisk ; set rh3:rh0 as inputs ; rh5:rh4 as outputs ; rh7:rh6 as inputs table 11-10: portk functions pin name function tris setting i/o i/o type description rk0/seg56 rk0 0 o dig latk<0> data output. 1 i st portk<0> data input. seg56 0 o ana lcd segment 56 output; dis ables all other pin functions. rk1/seg57 rk1 0 o dig latk<1> data output. 1 i st portk<1> data input. seg57 0 o ana lcd segment 57 output; dis ables all other pin functions. rk2/seg58 rk2 0 o dig latk<2> data output. 1 i st portk<2> data input. seg58 0 o ana lcd segment 58 output; dis ables all other pin functions. rk3/seg59 rk3 0 o dig latk<3> data output. 1 i st portk<3> data input. seg59 0 o ana lcd segment 59 output; dis ables all other pin functions. rk4/seg60 rk4 0 o dig latk<4> data output. 1 i st portk<4> data input. seg60 0 o ana lcd segment 60 output; dis ables all other pin functions. rk5/seg61 rk5 0 o dig latk<5> data output. 1 i st portk<5> data input. seg61 0 o ana lcd segment 61 output; dis ables all other pin functions. rk6/seg62 rk6 0 o dig latk<6> data output. 1 i st portk<6> data input. seg62 0 o ana lcd segment 62 output; dis ables all other pin functions. rk7/seg63 rk7 0 o dig latk<7> data output. 1 i st portk<7> data input. seg63 0 o ana lcd segment 63 output; dis ables all other pin functions. legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
pic18f97j94 family ds30575a-page 220 ? 2012 microchip technology inc. 11.12 portl, latl and trisl registers portl is an 8-bit wide, bidirectional port. the corre- sponding data direction and output latch registers are trisl and latl. all pins on portl are implemented with schmitt trig- ger input buffers. each pin is individually configurable as an input or output. each of the portl pins has a weak internal pull-up. the pull-ups are provided to keep the inputs at a known state for the external memory interface while powering up. a single control bit can turn off all the pull-ups. this is performed by clearing bit, rlpu (padcfg<0>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on any device reset. example 11-11: initializing portl note: portl is available only on 100-pin devices. banksel portl ; select correct bank clrf portl ; initialize portl by ; clearing output latches clrf latl ; alternate method ; to clear output latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisl ; set rl3:rl0 as inputs ; rl5:rl4 as output ; rl7:rl6 as inputs table 11-11: portl functions pin name function tris setting i/o i/o type description rl0/seg48 rl0 0 o dig latl<0> data output. 1 i st portl<0> data input. seg48 0 o ana lcd segment 48 output; disables all other pin functions. rl1/seg49 rl1 0 o dig latl<1> data output. 1 i st portl<1> data input. seg49 0 o ana lcd segment 49 output; disables all other pin functions. rl2/seg50 rl2 0 o dig latl<2> data output. 1 i st portl<2> data input. seg50 0 o ana lcd segment 50 output; disables all other pin functions. rl3/seg51 rl3 0 o dig latl<3> data output. 1 i st portl<3> data input. seg51 0 o ana lcd segment 51 output; disables all other pin functions. rl4/seg52 rl4 0 o dig latl<4> data output. 1 i st portl<4> data input. seg52 0 o ana lcd segment 52 output; disables all other pin functions. rl5/seg53 rl5 0 o dig latl<5> data output. 1 i st portl<5> data input. seg53 0 o ana lcd segment 53 output; disables all other pin functions. rl6/seg54 rl6 0 o dig latl<6> data output. 1 i st portl<6> data input. seg54 0 o ana lcd segment 54 output; disables all other pin functions. rl7/seg55 rl7 0 o dig latl<7> data output. 1 i st portl<7> data input. seg55 0 o ana lcd segment 55 output; disables all other pin functions. legend: o = output, i = input, ana = analog signal, dig = digital output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option).
? 2012 microchip technology inc. ds30575a-page 221 pic18f97j94 family 11.13 parallel slave port portd can function as an 8-bit-wide parallel slave port (psp), or microprocessor port, when control bit, pspmode (pspcon<4>), is set. the port is asynchronously readable and writable by the external world through the rd control input pin (re0/ad8/lcdbias1/rp28/rd ) and wr control input pin (re1/ad9/lcdbias2/rp29/wr ). the psp can directly interface to an 8-bit micro- processor data bus. the external microprocessor can read or write the portd latch as an 8-bit latch. setting bit, pspmode, enables port pin, re0/ad8/lcdbias1/rp28/rd , to be the rd input, re1/ad9/lcdbias2/rp29/wr to be the wr input and re2/ad10/lcdbias3/rp30/cs to be the cs (chip select) input. for this functionality, the corre- sponding data direction bits of the trise register (trise<2:0>) must be configured as inputs (? 111 ?). a write to the psp occurs when both the cs and wr lines are first detected low and ends when either are detected high. the pspif and ibf flag bits (pir1<7> and pspcon<7>, respectively) are set when the write ends. a read from the psp occurs when both the cs and rd lines are first detected low. the data in portd is read out and the obf bit (pspcon<6>) is set. if the user writes new data to portd to set obf, the data is immediately read out, but the obf bit is not set. when either the cs or rd line is detected high, the portd pins return to the input state and the pspif bit is set. user applications should wait for pspif to be set before servicing the psp. when this happens, the ibf and obf bits can be polled and the appropriate action taken. the timing for the control signals in write and read modes is shown in figure 11-4 and figure 11-5 , respectively. figure 11-3: portd and porte block diagram (parallel slave port) note: the parallel slave port is available only in microcontroller mode. data bus wr latd rdx q d ck en qd en rd portd pin one bit of portd set interrupt flag pspif (pir1<7>) read chip select write rd cs wr note: the i/o pin has protection diodes to v dd and v ss . ttl ttl ttl ttl or portd rd latd data latch tris latch
pic18f97j94 family ds30575a-page 222 ? 2012 microchip technology inc. figure 11-4: parallel slave port write waveforms register 11-4: pspcon: paralle l slave port co ntrol register r-0 r-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ibf obf ibov pspmode ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ibf: input buffer full status bit 1 = a word has been received and is waiting to be read by the cpu 0 = no word has been received bit 6 obf: output buffer full status bit 1 = the output buffer still holds a previously written word 0 = the output buffer has been read bit 5 ibov: input buffer overflow detect bit 1 = a write occurred when a previously input word had not been read (must be cleared in software) 0 = no overflow occurred bit 4 pspmode: parallel slave port mode select bit 1 = parallel slave port mode 0 = general purpose i/o mode bit 3-0 unimplemented: read as ? 0 ? q1 q2 q3 q4 cs q1 q2 q3 q4 q1 q2 q3 q4 wr rd ibf obf pspif portd<7:0>
? 2012 microchip technology inc. ds30575a-page 223 pic18f97j94 family figure 11-5: parallel slave port read waveforms q1 q2 q3 q4 cs q1 q2 q3 q4 q1 q2 q3 q4 wr ibf pspif rd obf portd<7:0>
pic18f97j94 family ds30575a-page 224 ? 2012 microchip technology inc. 11.14 virtual port this device includes a single virtual port, which is used to construct a logically addressed 8-bit port from 8 physically unrelated pins on the device. the virtual port is controlled through the portvr, latvr and trisvr registers. these function identically to the port, lat and tris registers of the actual i/o ports. refer to section 11.1 ?i/o port pin capabilities? for more information. 11.15 pps-lite previous pic18 devices had i/o pins that were ?hard-wired? to a set of peripherals. for example, a port pin might have had the option of serving as an i/o pin, an analog input or as an interrupt source. in an effort to increase the flexibility of the parts, pic18f97j94 devices contain pps-lite (peripheral pin select-lite), which allows the developer to connect an internal peripheral to a subset of pins. pps-lite is similar to pps (available on pic18f products), but limits the user to interconnections within four sets of pin/peripheral groups. the pps-lite feature allows some flexibility in choosing which peripheral connects to any particular pin. this allows designs to be maximized for layout efficiency, and also may allow component changes without changing the printed circuit board design. the periph- eral pin select feature operates over a fixed subset of digital i/o pins (those designated as rpn pins). users may independently map the input and/or output of most digital peripherals to a limited set of these i/o pins. the pps-lite configuration is performed in software and does not require the device to be reprogrammed. hard- ware safeguards are included that prevent accidental or spurious changes to the peripheral mapping once it has been established. 11.15.1 available pins the pps-lite feature is used with a range of pins. all devices in the pic18f97j94 family contain a total of 47 remappable peripheral pins, labeled rp0 through rp46. pins that support pps-lite feature include the designation, ?rpn? in their full pin designation, where ?rp? designates a remappable peripheral and ?n? is the remappable pin number. for pic18f97j94 devices, rp41 through rp45 are digital inputs only. 11.15.2 available peripherals the peripherals managed by the peripheral pin select are all ?digital only? peripherals. these include general serial communications (usart and spi), general pur- pose timer clock inputs, timer related peripherals (input capture and output compare) and external interrupt inputs. in comparison, some digital only peripheral modules are not currently included in the peripheral pin select feature. this is because the peripheral?s function requires special i/o circuitry on a specific port and can- not be easily connected to multiple pins. these modules include i 2 c, usb, change notification inputs, rtcc alarm output and all modules with analog inputs, such as the a/d converter. a key difference between remappable and non-remappable peripherals is that remappable peripherals are not associated with a default i/o pin. the peripheral must always be assigned to a specific i/o pin before it can be used. in contrast, non-remappable peripherals are always available on a default pin, assum- ing that the peripheral is active and not conflicting with another peripheral. when a remappable peripheral is active on a given i/o pin, it takes priority over all other digital i/o and digital communication peripherals associated with the pin. priority is given, regardless of the type of peripheral that is mapped. remappable peripherals never take priority over any analog functions associated with the pin.
? 2012 microchip technology inc. ds30575a-page 225 pic18f97j94 family figure 11-6: structure of port shared with pps peripherals i/o tris enable q d ck wr lat/ tris latch i/o pin wr port data bus q d ck data latch read port read tris n 0 wr tris peripheral 2 output enable i/o peripheral ?n? output enable pio module output multiplexers output function read lat 0 1 open-drain selection peripheral input q peripheral 1 output enable 0 n 1 1 peripheral pin select 0 n i/o pin 0 i/o pin 1 i/o pin n 1 peripheral input pin selection select for the pin peripheral ?n? output data peripheral 2 output data peripheral 1 output data i/o lat/port data
pic18f97j94 family ds30575a-page 226 ? 2012 microchip technology inc. 11.15.3 controlling peripheral pin select peripheral pin select features are controlled through two sets of special function registers (sfrs): one to map peripheral inputs and one to map peripheral outputs. because they are separately controlled, a par- ticular peripheral?s input and output (if the peripheral has both) can be placed on any selectable function with the only constraint being that rpn peripherals and pins can only be mapped within their own group. it is not possible to map a peripheral to a pin outside of its group or vice versa. the association of a peripheral to a peripheral-selectable pin is handled in two different ways, depending if an input or output is being mapped. 11.15.3.1 input mapping the inputs of the peripheral pin select options are mapped on the basis of the peripheral; that is, a bit field associated with a peripheral dictates the pin it will be mapped to. the rpinrx registers (refer to register x-y and table x-y) contain sets of 4-bit fields, with each set associated with one of the remappable peripherals. programming a given peripheral?s bit field with an rpn value maps the rpn pin to that peripheral. for any given device, the valid range of values for any of the bit fields corresponds to the maximum number of peripheral pin selections supported by the device. the pps-lite peripheral inputs and associated rpn pins have been organized into four groups. it is not pos- sible to map a peripheral to an rpn pin which is outside of its group. to map a peripheral input signal to an rpn pin, use the 4-step process as indicated in table 11-13 . choose the signal and the rpn pin, and the column on the right shows which value to write to the associated rpin register. the peripheral inputs that support peripheral pin selection have no default pins. since the implemented bit fields of rpinrx registers reset to all ? 1 ?s, the inputs are all tied to v ss in the device?s default (reset) state. for example, to assign u1rx to rp2, write the value, h?0, to rpinr01<3:0>. figure 11-7 illustrates remappable pin selection for the u1rx input. figure 11-7: remappable input for u1rx rp0 rp1 rp2 rpn 0 n 1 2 u1rx input rpinr01<3:0> to peripheral
? 2012 microchip technology inc. ds30575a-page 227 pic18f97j94 family table 11-12: rpinr registers name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 rpinr52_53 pbio7r3 pbio7r2 pbio7r1 pbio7r0 pbio6r3 pbio6r2 pbio6r1 pbio6r0 rpinr50_51 pbio5r3 pbio5r2 pbio5r1 pbio5r0 pbio4r3 pbio4r2 pbio4r1 pbio4r0 rpinr48_49 pbio3r3 pbio3r2 pbio3r1 pbio3r0 pbio2r3 pbio2r2 pbio2r1 pbio2r0 rpinr46_47 pbio1r3 pbio1r2 pbio1r1 pbio1r0 pbio0r3 pbio0r2 pbio0r1 pbio0r0 rpinr44_45 t5ckir3 t5ckir2 t5ckir1 t5ckir0 t5gr3 t5gr2 t5gr1 t5gr0 rpinr42_43 t3ckir3 t3ckir2 t3ckir1 t3ckir0 t3gr3 t3gr2 t3gr1 t3gr0 rpinr40_41 t1ckir3 t1ckir2 t1ckir1 t1ckir0 t1gr3 t1gr2 t1gr1 t1gr0 rpinr38_39 t0ckir3 t0ckir2 t0ckir1 t0ckir0 ccp10r3 ccp10r2 ccp10r1 ccp10r0 rpinr36_37 ccp9r3 ccp9r2 ccp9r1 ccp 9r0 ccp8r3 ccp8r2 ccp8r1 ccp8r0 rpinr34_35 ccp7r3 ccp7r2 ccp7r1 ccp 7r0 ccp6r3 ccp6r2 ccp6r1 ccp6r0 rpinr32_33 ccp5r3 ccp5r2 ccp5r1 ccp 5r0 ccp4r3 ccp4r2 ccp4r1 ccp4r0 rpinr30_31 mdcin2r3 mdcin2r2 mdcin2r1 mdcin2r0 mdcin1r3 mdcin1r2 mdcin1r1 mdcin1r0 rpinr28_29 mdminr3 mdminr2 mdminr1 mdminr0 int3r3 int3r2 int3r1 int3r0 rpinr26_27 int2r3 int2r2 int2r1 int2r0 int1r3 int1r2 int1r1 int1r0 rpinr24_25 ioc7r3 ioc7r2 ioc7r1 ioc7r0 ioc6r3 ioc6r2 ioc6r1 ioc6r0 rpinr22_23 ioc5r3 ioc5r2 ioc5r1 ioc5r0 ioc4r3 ioc4r2 ioc4r1 ioc4r0 rpinr20_21 ioc3r3 ioc3r2 ioc3r1 ioc3r0 ioc2r3 ioc2r2 ioc2r1 ioc2r0 rpinr18_19 ioc1r3 ioc1r2 ioc1r1 ioc1r0 ioc0r3 ioc0r2 ioc0r1 ioc0r0 rpinr16_17 eccp3r3 eccp3r2 eccp3r1 eccp3r0 eccp2r3 eccp2r2 eccp2r1 eccp2r0 rpinr14_15 eccp1r3 eccp1r2 eccp1r1 eccp1r0 flt0r3 flt0r2 flt0r1 flt0r0 rpinr12_13 ss2r3 ss2r2 ss2r1 ss2r0 sdi2r3 sdi2r2 sdi2r1 sdi2r0 rpinr10_11 sck2r3 sck2r2 sck2r1 sck2r0 ss1r3 ss1r2 ss1r1 ss1r0 rpinr8_9 sdi1r3 sdi1r2 sdi1r1 sdi1r0 sck1r3 sck1r2 sck1r1 sck1r0 rpinr6_7 u4txr3 u4txr2 u4txr1 u4txr0 u4rxr3 u4rxr2 u4rxr1 u4rxr0 rpinr4_5 u3txr3 u3txr2 u3txr1 u3txr0 u3rxr3 u3rxr2 u3rxr1 u3rxr0 rpinr2_3 u2txr3 u2txr2 u2txr1 u2txr0 u2rxr3 u2rxr2 u2rxr1 u2rxr0 rpinr0_1 u1txr3 u1txr2 u1txr1 u1txr0 u1rxr3 u1rxr2 u1rxr1 u1rxr0
pic18f97j94 family ds30575a-page 228 ? 2012 microchip technology inc. table 11-13: rpin register s and available functions pps-lite input peripheral group 4n pps-lite input peripheral group 4n + 1 (1) to map this signal (4) to the associated rpin register (1) to map this signal (4) to the associated rpin register sdi1 rpinr8_9<7:4> sdi2 rpinr12_13<3:0> flt0 rpinr14_15<3:0> int1 rpinr26_27<3:0> ioc0 rpinr18_19<3:0> ioc1 rpinr18_19<7:4> ioc4 rpinr22_23<3:0> ioc5 rpinr22_23<7:4> mdcin1 rpinr30_31<3:0> mdcin2 rpinr30_31<7:4> t0cki rpinr38_39<7:4> t1cki rpinr40_41<7:4> t5g rpinr44_45<3:0> t1g rpinr40_41<3:0> u3rx rpinr4_5<3:0> t3cki rpinr42_43<7:4> u4rx rpinr6_7<3:0> t3g rpinr42_43<3:0> ccp5 rpinr32_33<7:4> t5cki rpinr44_45<7:4> ccp8 rpinr36_37<3:0> u3tx rpinr4_5<7:4> pbio0 rpinr46_47<3:0> u4tx rpinr6_7<7:4> pbio4 rpinr50_51<3:0> ccp7 rpinr34_35<7:4> ccp9 rpinr36_37<7:4> pbio1 rpinr46_47<7:4> pbio5 rpinr50_51<7:4> (2) with this rpn pin (3) write this corresponding value ( 2) with this rpn pin (3) write this corresponding value rp0 h?0 rp1 h?0 rp4 h?1 rp5 h?1 rp8 h?2 rp9 h?2 rp12 h?3 rp13 h?3 rp16 h?4 rp17 h?4 rp20 h?5 rp21 h?5 rp24 h?6 rp25 h?6 rp28 h?7 rp29 h?7 rp32 h?8 rp33 h?8 rp36 h?9 rp37 h?9 rp40 h?a rp41 h?a rp44 h?b rp45 h?b ? h?c ? h?c ? h?d ? h?d ? h?e ? h?e v ss h?f v ss h?f
? 2012 microchip technology inc. ds30575a-page 229 pic18f97j94 family 11.15.3.2 output mapping in contrast to the inputs, the outputs of the peripheral pin select options are mapped on the basis of the pin. in this case, a bit field associated with a particular pin dictates the peripheral output to be mapped. the rporx registers contain sets of 4-bit fields, with each associated with one rpn pin (see register 11-5 ). the value of the bit field corresponds to one of the periph- erals and that peripheral?s output is mapped to the pin. each pin has a limited set of peripherals to choose from. the pps-lite peripheral outputs and associated rpn pins have been organized into four groups. it is not possible to map a peripheral to an rpn pin which is out- side of its group. to map a peripheral output signal to an rpn pin, use the 4-step process, as indicated in table 11-14 . choose the rpn pin and the signal; the column on the right shows which value to write to the associated rporx register. the peripheral outputs that support peripheral pin selection have no default pins. since the rporx reg- isters reset to all ? 0 ?s, the outputs are all disconnected in the device?s default (reset) state. the list of peripherals for output mapping also includes a null value of b?0000? because of the mapping technique. this allows unused peripherals to not be connected to a pin. not all peripherals are available on all pins. for example, the ?sdo2? signal is only avail- able on rp0, rp4, rp8, etc. the ?sdo2? signal is not available on rp1. pps-lite input peripheral group 4n + 2 pps-lite input peripheral group 4n + 3 (1) to map this signal (4) to the associated rpin register (1) to map this signal (4) to the associated rpin register ss1 rpinr10_11<3:0> ss2 rpinr12_13<7:4> int2 rpinr26_27<7:4> int3 rpinr28_29<3:0> ioc2 rpinr20_21<3:0> ioc3 rpinr20_21<7:4> ioc6 rpinr24_25<3:0> ioc7 rpinr24_25<7:4> mdmin rpinr28_29<7:4> u1rx rpinr0_1<3:0> u1tx rpinr0_1<7:4> u2tx rpinr2_3<7:4> u2rx rpinr2_3<3:0> sck1 rpinr8_9<3:0> sck2 rpinr10_11<7:4> eccp1 rpinr14_15<7:4> eccp3 rpinr16_17<7:4> eccp2 rpinr16_17<3:0> ccp6 rpinr34_35<3:0> ccp4 rpinr32_33<3:0> ccp10 rpinr38_39<3:0> pbio3 rpinr48_49<7:4> pbio2 rpinr48_49<3:0> pbio7 rpinr52_53<7:4> pbio6 rpinr52_53<3:0> (2) with this rpn pin (3) write this corresponding value ( 2) with this rpn pin (3) write this corresponding value rp2 h?0 rp3 h?0 rp6 h?1 rp7 h?1 rp10 h?2 rp11 h?2 rp14 h?3 rp15 h?3 rp18 h?4 rp19 h?4 rp22 h?5 rp23 h?5 rp26 h?6 rp27 h?6 rp30 h?7 rp31 h?7 rp34 h?8 rp35 h?8 rp38 h?9 rp39 h?9 rp42 h?a rp43 h?a rp46 h?b ? h?b ? h?c ? h?c ? h?d ? h?d ? h?e ? h?e v ss h?f v ss h?f table 11-13: rpin registers and available functions (continued)
pic18f97j94 family ds30575a-page 230 ? 2012 microchip technology inc. figure 11-8: multiplexing of remappable output for rpn 0 3 rporn<3:0> i/o tris setting u1tx output enable u1rts output enable 4 22 oc5 output enable 0 3 i/o lat/port content u1tx output u1rts output 4 22 oc5 output output enable output data rpn register 11-5: rporn_n: remapped peripheral output register n (function maps to pin) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 rporn_3 rporn_2 rporn_1 rporn_0 rpirm_3 rpirm_2 rpirm_1 rpirm_0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 rporn_<3:0>: rpn peripheral output function mapping bit 3-0 rpmr<3:0>: rpm peripheral output function mapping note 1: register values can only be changed if iolock = 0 .
? 2012 microchip technology inc. ds30575a-page 231 pic18f97j94 family table 11-14: pps-lite output pps-lite output peripheral group 4n pps-lite output peripheral group 4n + 1 (1) to map this rpn pin (4) to the associated rpor register (1) to map this rpn pin (4) to the associated rpor register rp0 rpor0_1<3:0> rp1 rpor0_1<7:4> rp4 rpor4_5<3:0> rp5 rpor4_5<7:4> rp8 rpor8_9<3:0> rp9 rpor8_9<7:4> rp12 rpor12_13<3:0> rp13 rpor12_13<7:4> rp16 rpor16_17<3:0> rp17 rpor16_17<7:4> rp20 rpor20_21<3:0> rp21 rpor20_21<7:4> rp24 rpor24_25<3:0> rp25 rpor24_25<7:4> rp28 rpor28_29<3:0> rp29 rpor28_29<7:4> rp32 rpor32_33<3:0> rp33 rpor32_33<7:4> rp36 rpor36_37<3:0> rp37 rpor36_37<7:4> rp40 rpor40_41<3:0> rp41 rpor40_41<7:4> rp44 rpor44_45<3:0> rp45 rpor44_45<7:4> (2) with this output signal (3) write this corres ponding value (2) with this output si gnal (3) write this corresponding value disabled h?0 disabled h?0 u2bclk h?1 u1bclk h?1 u3rx_dt h?2 u3tx_ck h?2 u4rx_dt h?3 u4tx_ck h?3 sdo2 h?4 sdo1 h?4 p1d h?5 p1c h?5 p2d h?6 p2c h?6 p3b h?7 p3c h?7 ctpls h?8 ccp7 h?8 ccp5 h?9 ccp9 h?9 ccp8 h?a c2out h?a c1out h?b unused h?b unused h?c unused h?c pbio0 h?d pbio1 h?d pbio4 h?e pbio5 h?e reserved h?f reserved h?f
pic18f97j94 family ds30575a-page 232 ? 2012 microchip technology inc. 11.15.3.3 i/o mapping while most peripheral signals are defined as either input or output, some peripheral signals switch between input and output: unrx_dt, untx_ck, pbio and ccp. most commonly, these signals are mapped so that both the input and output map to the same rpn pin. if desired, the input and output can be mapped to separate pins. for standard peripheral operation, ensure that both the input and output mapping configurations select the same rpn pin. 11.15.3.4 mapping limitations the control schema of peripheral select pins is not lim- ited to a small range of fixed peripheral configurations. there are no mutual or hardware enforced lockouts between any of the peripheral mapping sfrs. while such mappings may be technically possible from a configuration point of view, the user must ensure the selected configurations are supportable from an electrical point of view. 11.15.4 controlling configuration changes because peripheral remapping can be changed during run time, some restrictions on peripheral remapping are needed to prevent accidental configuration changes. pic18f97j94 devices include two features to prevent alterations to the peripheral map: ? continuous state monitoring ? configuration bit remapping lock pps-lite output peripheral group 4n + 2 pps-lite output peripheral group 4n +3 (1) to map this rpn pin (4) to the associated rpor register (1) to map this rpn pin (4) to the associated rpor register rp2 rpor2_3<3:0> rp3 rpor2_3<7:4> rp6 rpor6_7<3:0> rp7 rpor6_7<7:4> rp10 rpor10_11<3:0> rp11 rpor10_11<7:4> rp14 rpor14_15<3:0> rp15 rpor14_15<7:4> rp18 rpor18_19<3:0> rp19 rpor18_19<7:4> rp22 rpor22_23<3:0> rp23 rpor22_23<7:4> rp26 rpor26_27<3:0> rp27 rpor26_27<7:4> rp30 rpor30_31<3:0> rp31 rpor30_31<7:4> rp34 rpor34_35<3:0> rp35 rpor34_35<7:4> rp38 rpor38_39<3:0> rp39 rpor38_39<7:4> rp42 rpor42_43<3:0> rp43 rpor42_43<7:4> rp46 rpor46<3:0> (2) with this output signal (3) write this corres ponding value (2) with this output si gnal (3) write this corresponding value disabled h?0 disabled h?0 u1tx_ck h?1 u1rx_dt h?1 u2rx_dt h?2 u2tx_ck h?2 u3bclk h?3 sck1 h?3 u4bclk h?4 eccp1/p1a h?4 sck2 h?5 eccp2/p2a h?5 p1b h?6 p3d h?6 p2b h?7 mdout h?7 eccp3/p3a h?8 ccp4 h?8 ccp6 h?9 c3out h?9 ccp10 h?a unused h?a unused h?b unused h?b unused h?c unused h?c pbio2 h?d pbio3 h?d pbio6 h?e pbio7 h?e reserved h?f reserved h?f table 11-14: pps-lite output (continued)
? 2012 microchip technology inc. ds30575a-page 233 pic18f97j94 family 11.15.4.1 control register lock the contents of rpinrx and rporx registers are con- stantly monitored in hardware by shadow registers. if an unexpected change in any of the registers occurs (such as cell disturbances caused by esd or other external events), a configuration mismatch reset will trigger. 11.15.4.2 configuration bit pin select lock as an additional level of safety, the device can be configured to prevent more than one write session to the rpinrx and rporx registers. the iol1way con- figuration bit (config5h<0>) blocks the iolock bit from being cleared after it has been set once. in the default (unprogrammed) state, iol1way is set, restricting users to one write session. programming iol1way allows users unlimited access to the periph- eral pin select registers. it is good programming prac- tice to always set the iolock bit (osccon2<6>) after all changes have been made to pps-lite registers. 11.15.5 considerations for peripheral pin selection the ability to control peripheral pin selection intro- duces several considerations into application design that should be considered. this is particularly true for several common peripherals which are only available as remappable peripherals. before any other application code is executed, the user must initialize the device with the proper peripheral configuration. since the iolock is not active in the reset state, the peripherals can be configured, and the iolock bit can be set when configuration is complete. choosing the configuration requires the review of all peripheral pin selects and their pin assignments, especially those that will not be used in the application. in all cases, unused pin-selected peripherals should be disabled. unused peripherals should have their inputs assigned to v ss . i/o pins with unused rpn functions should be configured with the null (? 0 ?) peripheral output. the assignment of an rpn pin to the peripheral input or output depends on the peripheral and its use in the application. it is good programming practice to map peripherals to pins immediately after reset. this should be done before any configuration changes to the peripheral itself. the assignment of a peripheral output to a particular pin does not automatically perform any other configura- tion of the pin?s i/o circuitry. this means adding a pin-selectable output to a pin may mean inadvertently driving an existing peripheral input when the output is driven. users must be familiar with the behavior of other fixed peripherals that share a remappable pin. to be safe, fixed digital peripherals that share the same pin should be disabled when not in use. configuring a remappable pin for a specific peripheral input does not automatically turn that feature on. the peripheral must be specifically configured for operation and enabled, as if it were tied to a fixed pin. a final consideration is that peripheral pin select func- tions neither override analog inputs, nor reconfigure pins with analog functions for digital i/o. if a pin is configured as an analog input on device reset, it must be explicitly reconfigured as digital i/o when used with a peripheral pin select. 11.15.5.1 basic steps to use peripheral pin selection lite (pps-lite) 1. disable any fixed digital peripherals on the pins to be used. 2. switch pins to be used for digital functionality (if they have analog functionality) using the anconx registers. 3. clear the iolock bit (osccon<6>) if needed (not needed after a device reset). 4. set rpinrx and rporx registers appropriately. 5. set the iolock bit (osccon<6>). 6. enable and configure newly mapped pps-lite peripherals.
pic18f97j94 family ds30575a-page 234 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 235 pic18f97j94 family 12.0 data signal modulator the data signal modulator (dsm) is a peripheral which allows the user to mix a data stream, also known as a modulator signal, with a carrier signal to produce a modulated output. both the carrier and the modulator signals are supplied to the dsm module, either internally from the output of a peripheral, or externally through an input pin. the carrier signal is comprised of two distinct and separate signals: a carrier high (carh) signal and a carrier low (carl) signal. during the time in which the modulator (mod) signal is in a logic high state, the dsm mixes the carrier high signal with the modulator signal. when the modulator signal is in a logic low state, the dsm mixes the carrier low signal with the modulator signal. using this method, the dsm can generate the following types of key modulation schemes: ? frequency-shift keying (fsk) ? phase-shift keying (psk) ? on-off keying (ook) additionally, the following features are provided within the dsm module: ? carrier synchronization ? carrier source polarity select ? carrier source pin disable ? programmable modulator data ? modulator source pin disable ? modulator output polarity select ? slew rate control figure 12-1 shows a simplified block diagram of the data signal modulator peripheral.
pic18f97j94 family ds30575a-page 236 ? 2012 microchip technology inc. figure 12-1: simplified block diagram of the data signal modulator d q mdbit mdmin mssp1 (sdo) mssp2 (sdo) eusart1 (tx x ) eusart2 (tx x ) eusart3 (tx x ) eusart4 (tx x ) v ss mdcin1 mdcin2 refo1 clock eccp1 eccp2 eccp3 ccp4 0000 0001 0010 0011 0100 0101 0110 0111 1000 1011 1001 mdch<3:0> mdsrc<3:0> mdcl<3:0> eccp1 eccp2 sync mdchpol mdclpol d q 1 0 sync 1 0 mdchsync mdclsync mdout mdopol mdoe carh carl en mden data signal modulator mod ccp5 ccp6 1010 ccp7 ccp8 1100 1101 1110 ccp9 1111 ccp10 refo2 clock system clock eccp3 ccp4 ccp5 ccp6 ccp7 ccp8 v ss mdcin1 mdcin2 refo1 clock eccp1 eccp2 eccp3 ccp4 ccp5 ccp6 ccp7 ccp8 ccp9 ccp10 refo2 c lock system clock switches between port function and dsm output 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1101 1011 1100 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111 1000 1011 1001 1010 1100 1101 1110 1111
? 2012 microchip technology inc. ds30575a-page 237 pic18f97j94 family 12.1 dsm operation the dsm module can be enabled by setting the mden bit in the mdcon register. clearing the mden bit in the mdcon register disables the dsm module by auto- matically switching the carrier high and carrier low signals to the v ss signal source. the modulator signal source is also switched to the mdbit in the mdcon register. this not only assures that the dsm module is inactive, but that it is also consuming the least amount of current. the modulation carrier high and modulation carrier low control registers are not affected when the mden bit is cleared, and the dsm module is disabled. the values inside these registers remain unchanged while the dsm is inactive. the sources for the carrier high, carrier low and modulator signals will once again be selected when the mden bit is set, and the dsm module is again enabled and active. the modulated output signal can be disabled without shutting down the dsm module. the dsm module will remain active and continue to mix signals, but the out- put value will not be sent to the mdout pin. during the time that the output is disabled, the mdout pin will remain low. the modulated output can be disabled by clearing the mdoe bit in the mdcon register. 12.2 modulator signal sources the modulator signal can be supplied from the following sources: ? eccp1 signal ? eccp2 signal ? eccp3 signal ? ccp2 signal ? ccp3 signal ? ccp4 signal ? ccp5 signal ? ccp6 signal ? ccp7 signal ? ccp8 signal ? mssp1 sdo signal (spi mode only) ? mssp2 sdo signal (spi mode only) ? eusart1 tx1 signal ? eusart2 tx2 signal ? eusart3 tx3 signal ? eusart4 tx4 signal ? external signal on mdmin pin (rf0/mdmin) ? mdbit bit in the mdcon register the modulator signal is selected by configuring the mdsrc<3:0> bits in the mdsrc register. 12.3 carrier signal sources the carrier high signal and carrier low signal can be supplied from the following sources: ? eccp1 signal ? eccp2 signal ? eccp3 signal ? ccp5 signal ? ccp6 signal ? ccp7 signal ? ccp8 signal ? ccp9 signal ? ccp10 signal ? reference clock output module signal (refo1) ? reference clock output module signal (refo2) ?system clock ? external signals on the mdcin1 and mdcin2 pins are available though pps. refer to section 11.15 ?pps-lite? for setup. ?v ss the carrier high signal is selected by configuring the mdch<3:0> bits in the mdcarh register. the carrier low signal is selected by configuring the mdcl<3:0> bits in the mdcarl register. 12.4 carrier synchronization during the time when the dsm switches between carrier high and carrier low signal sources, the carrier data in the modulated output signal can become truncated. to prevent this, the carrier signal can be synchronized to the modulator signal. when synchroni- zation is enabled, the carrier pulse that is being mixed at the time of the transition is allowed to transition low before the dsm switches over to the next carrier source. synchronization is enabled separately for the carrier high and carrier low signal sources. synchronization for the carrier high signal can be enabled by setting the mdchsync bit in the mdcarh register. synchro- nization for the carrier low signal can be enabled by setting the mdclsync bit in the mdcarl register. figure 12-1 through figure 12-6 show timing diagrams using various synchronization methods.
pic18f97j94 family ds30575a-page 238 ? 2012 microchip technology inc. figure 12-2: on-off keying (ook) synchronization figure 12-3: no synchronization (mdchsync = 0 , mdclsync = 0 ) figure 12-4: carrier high synchronization (mdchsync = 1 , mdclsync = 0 ) carrier low (carl) mdchsync = 1 mdclsync = 0 mdchsync = 1 mdclsync = 1 mdchsync = 0 mdclsync = 0 mdchsync = 0 mdclsync = 1 carrier high (carh) modulator (mod) mdchsync = 0 mdclsync = 0 modulator (mod) carrier high (carh) carrier low (carl) active carrier carh carl carl carh state mdchsync = 1 mdclsync = 0 modulator (mod) carrier high (carh) carrier low (carl) active carrier carh carl carl carh state both both
? 2012 microchip technology inc. ds30575a-page 239 pic18f97j94 family figure 12-5: carrier low synchronization (mdchsync = 0 , mdclsync = 1 ) figure 12-6: full synchronization (mdchsync = 1 , mdclsync = 1 ) mdchsync = 0 mdclsync = 1 modulator (mod) carrier high (carh) carrier low (carl) active carrier carh carl carl carh state mdchsync = 1 mdclsync = 1 modulator (mod) carrier high (carh) carrier low (carl) active carrier carh carl carl carh state falling edges used to sync
pic18f97j94 family ds30575a-page 240 ? 2012 microchip technology inc. 12.5 carrier source polarity select the signal provided from any selected input source for the carrier high and carrier low signals can be inverted. inverting the signal for the carrier high source is enabled by setting the mdchpol bit of the mdcarh register. inverting the signal for the carrier low source is enabled by setting the mdclpol bit of the mdcarl register. 12.6 carrier source pin disable some peripherals assert control over their correspond- ing output pin when they are enabled. for example, when the ccp1 module is enabled, the output of ccp1 is connected to the ccp1 pin. this default connection to a pin can be disabled by setting the mdchodis bit in the mdcarh register for the carrier high source and the mdclodis bit in the mdcarl register for the carrier low source. 12.7 programmable modulator data the mdbit of the mdcon register can be selected as the source for the modulator signal. this gives the user the ability to program the value used for modulation. 12.8 modulator source pin disable the modulator source default connection to a pin can be disabled by setting the mdsodis bit in the mdsrc register. 12.9 modulated output polarity the modulated output signal provided on the mdout pin can also be inverted. inverting the modulated out- put signal is enabled by setting the mdopol bit of the mdcon register. 12.10 slew rate control when modulated data streams of 20 mhz or greater are required, the slew rate limitation on the output port pin can be disabled. the slew rate limitation can be removed by clearing the mdslr bit in the mdcon register. 12.11 operation in sleep mode the dsm module is not affected by sleep mode. the dsm can still operate during sleep if the carrier and modulator input sources are also still operable during sleep. 12.12 effects of a reset upon any device reset, the modulator data signal module is disabled. the user?s firmware is responsible for initializing the module before enabling the output. the registers are reset to their default values.
? 2012 microchip technology inc. ds30575a-page 241 pic18f97j94 family register 12-1: mdcon: modu lation control register r/w-0 r/w-0 r/w-1 r/w-0 r/w-0 u-0 u-0 r/w-0 mden mdoe mdslr mdopol mdout ( 2 ) ? ?mdbit ( 1 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mden: modulator module enable bit 1 = modulator module is enabled and mixing input signals 0 = modulator module is disabled and has no output bit 6 mdoe: modulator module pin output enable bit 1 = modulator pin output is enabled 0 = modulator pin output is disabled bit 5 mdslr: mdout pin slew rate limiting bit 1 = mdout pin slew rate limiting is enabled 0 = mdout pin slew rate limiting is disabled bit 4 mdopol: modulator output polarity select bit 1 = modulator output signal is inverted 0 = modulator output signal is not inverted bit 3 mdout: modulator output bit ( 2 ) displays the current output value of the modulator module. bit 2-1 unimplemented: read as ? 0 ? bit 0 mdbit: modulator source input bit ( 1 ) allows software to manually set modulation source input to the module. note 1: the mdbit must be selected as the modulation source in the mdcon register for this operation. 2: the modulated output frequency can be greater and asynchronous from the clock that updates this register bit. the bit value may not be valid for higher speed modulator or carrier signals.
pic18f97j94 family ds30575a-page 242 ? 2012 microchip technology inc. register 12-2: mdsrc: modulat ion source control register r/w-x u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x mdsodis ? ? ? mdsrc3 mdsrc2 mdsrc1 mdsrc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mdsodis: modulation source output disable bit 1 = output signal driving the peripheral output pin (selected by mdms<3:0>) is disabled 0 = output signal driving the peripheral output pin (selected by mdms<3:0>) is enabled bit 6-4 unimplemented: read as ? 0 ? bit 3-0 mdsrc<3:0> modulation source selection bits 1111 = ccp8 output (pwm output mode only) 1110 = ccp7 output (pwm output mode only) 1101 = ccp6 output (pwm output mode only) 1100 = ccp5 output (pwm output mode only) 1011 = ccp4 output (pwm output mode only) 1010 = eccp3 output (pwm output mode only) 1001 = eccp2 output (pwm output mode only) 1000 = eccp1 output (pwm output mode only) 0111 = eusart4 txx output 0110 = eusart3 txx output 0101 = eusart2 txx output 0100 = eusart1 txx output 0011 = mssp2 sdo signal (spi mode only) 0010 = mssp1 sdo signal (spi mode only) 0001 = mdmin pin 0000 = mdbit bit of mdcon register is the modulation source
? 2012 microchip technology inc. ds30575a-page 243 pic18f97j94 family register 12-3: mdcarh: modulation carrier high control register r/w-x r/w-x r/w-x u-0 r/w-x r/w-x r/w-x r/w-x mdchodis mdchpol mdchsync ? mdch3 ( 1 ) mdch2 ( 1 ) mdch1 ( 1 ) mdch0 ( 1 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mdchodis: modulator carrier high output disable bit 1 = output signal driving the peripheral output pin (selected by mdch<3:0>) is disabled 0 = output signal driving the peripheral output pin (selected by mdch<3:0>) is enabled bit 6 mdchpol: modulator carrier high polarity select bit 1 = selected carrier high signal is inverted 0 = selected carrier high signal is not inverted bit 5 mdchsync: modulator carrier high synchronization enable bit 1 = modulator waits for a falling edge on the carrier high time signal before allowing a switch to the carrier low time 0 = modulator output is not synchronized to the carrier high time signal ( 1 ) bit 4 unimplemented: read as ? 0 ? bit 3-0 mdch<3:0>: modulator data carrier high selection bits ( 1 ) 1111 = reference clock output module 2 (refo2) signal 1110 = system clock 1101 = ccp10 output (pwm output mode only) 1100 = ccp9 output (pwm output mode only) 1011 = ccp8 output (pwm output mode only) 1010 = ccp7 output (pwm output mode only) 1001 = ccp6 output (pwm output mode only) 1000 = ccp5 output (pwm output mode only) 0111 = ccp4 output (pwm output mode only) 0110 = eccp3 output (pwm output mode only) 0101 = eccp2 output (pwm output mode only) 0100 = eccp1 output (pwm output mode only) 0011 = reference clock output module 1 (refo1) signal 0010 = mdcin2 pin 0001 = mdcin1 pin 0000 = no carrier input (tied to ground) note 1: narrowed carrier pulse widths or spurs may occur in the signal stream during transitions.
pic18f97j94 family ds30575a-page 244 ? 2012 microchip technology inc. register 12-4: mdcarl: modulatio n carrier low control register r/w-x r/w-x r/w-x u-0 r/w-x r/w-x r/w-x r/w-x mdclodis mdclpol mdclsync ? mdcl3 ( 1 ) mdcl2 ( 1 ) mdcl1 ( 1 ) mdcl0 ( 1 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mdclodis: modulator carrier low output disable bit 1 = output signal driving the peripheral output pin (selected by mdcl<3:0>) is disabled 0 = output signal driving the peripheral output pin (selected by mdcl<3:0>) is enabled bit 6 mdclpol: modulator carrier low polarity select bit 1 = selected carrier low signal is inverted 0 = selected carrier low signal is not inverted bit 5 mdclsync: modulator carrier low synchronization enable bit 1 = modulator waits for a falling edge on the carrier low time signal before allowing a switch to the carrier high time 0 = modulator output is not synchronized to the carrier low time signal ( 1 ) bit 4 unimplemented: read as ? 0 ? bit 3-0 mdcl<3:0>: modulator data carrier low selection bits ( 1 ) 1111 = reference clock output module 2 (refo2) signal 1110 = system clock 1101 = ccp10 output (pwm output mode only) 1100 = ccp9 output (pwm output mode only) 1011 = ccp8 output (pwm output mode only) 1010 = ccp7 output (pwm output mode only) 1001 = ccp6 output (pwm output mode only) 1000 = ccp5 output (pwm output mode only) 0111 = ccp4 output (pwm output mode only) 0110 = eccp3 output (pwm output mode only) 0101 = eccp2 output (pwm output mode only) 0100 = eccp1 output (pwm output mode only) 0011 = reference clock output module 1 (refo1) signal 0010 = mdcin2 pin 0001 = mdcin1 pin 0000 = no carrier input (tied to ground) note 1: narrowed carrier pulse widths or spurs may occur in the signal stream during transitions.
? 2012 microchip technology inc. ds30575a-page 245 pic18f97j94 family 13.0 liquid crystal display (lcd) controller the liquid crystal display (lcd) driver module gener- ates the timing control to drive a static or multiplexed lcd panel. in 100-pin devices (pic18f97j94), the module drives panels of up to eight commons and up to 60 segments when 5 to 8 commons are used, and up to 64 segments when 1 to 4 commons are used. it also provides control of the lcd pixel data. the lcd driver module supports: ? direct driving of lcd panel ? three lcd clock sources with selectable prescaler ? up to eight commons: - static (one common) - 1/2 multiplex (two commons) - 1/3 multiplex (three commons) - 1/8 multiplex (eight commons) ? up to 60 segments (in 100-pin devices when 1/5-1/8 multiplex is selected), 64 (in 100-pin devices when up to 1/4 multiplex is selected), 46 (in 80-pin devices when 1/5-1/8 multiplex is selected), 50 (in 80-pin devices when up to 1/4 multiplex is selected), 30 (in 64-pin devices when 1/5-1/8 multiplex is selected) and 34 (in 64-pin devices when up to 1/4 multiplex is selected) ? static, 1/2 or 1/3 lcd bias ? on-chip bias generator with dedicated charge pump to support a range of fixed and variable bias options ? internal resistors for bias voltage generation ? software contrast control for lcd using the internal biasing a simplified block diagram of the module is shown in figure 13-1 . figure 13-1: lcd contro ller module block diagram com<7:0> timing control data bus sosc frc oscillator lprc oscillator 512 to 64 mux seg<63:0> to i/o pins 64 x 8 lcd data lcdconl lcdpsl lcdsex lcddata0 lcddata1 lcddata62 lcddata63 . . . lcd bias generation lcd clock source select lcd charge pump 64 8 bias voltage 8 (secondary oscillator) resistor ladder
pic18f97j94 family ds30575a-page 246 ? 2012 microchip technology inc. 13.1 lcd registers the lcd controller has up to 77 registers: ? lcd control register (lcdcon) ? lcd phase register (lcdps) ? lcd voltage regulator control register (lcdreg) ? lcd reference ladder control register high/low (lcdrefh and lcdrefl) ? eight lcd segment enable registers (lcdse7:lcdse0) ? 64 lcd data registers (lcddata63:lcddata0) the lcdcon register, shown in register 13-1 , con- trols the overall operation of the module. once the module is configured, the on (lcdcon<15>) bit is used to enable or disable the lcd module. the lcd panel can also operate during sleep by clearing the slpen (lcdcon<6>) bit. the lcdps register, shown in register 13-3 , configures the lcd clock source prescaler and the type of wave- form: type-a or type-b. for details on these features, see section 13.3 ?lcd clock source selection? and section 13.12 ?lcd waveform generation? . register 13-1: lcdcon: lcd control register r/w-0 r/w-0 r/c-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 on slpen werr cs1 cs0 lmux2 lmux1 lmux0 bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 on : lcd driver enable bit 1 = lcd driver module is enabled 0 = lcd driver module is disabled bit 6 slpen : lcd driver enable in sleep mode bit 1 = lcd driver module is disabled in sleep mode 0 = lcd driver module is enabled in sleep mode bit 5 werr : lcd write failed error bit 1 = lcddatax register is written while wa (lcdps<4>) = 0 (must be cleared in software) 0 = no lcd write error bit 4-3 cs<1:0> : clock source select bits 00 = frc (8 mhz)/8192 01 = sosc oscillator (32.768 khz)/32 1x = intrc (31.25 khz)/32 bit 2-0 lmux<2:0> : commons select bits lmux<2:0> multiplex bias 111 1/8 mux (com<7:0>) 1/3 110 1/7 mux (com<6:0>) 1/3 101 1/6 mux (com<5:0>) 1/3 100 1/5 mux (com<4:0>) 1/3 011 1/4 mux (com<3:0>) 1/3 010 1/3 mux (com<2:0>) 1/2 or 1/3 001 1/2 mux (com<1:0>) 1/2 or 1/3 000 static (com0) static
? 2012 microchip technology inc. ds30575a-page 247 pic18f97j94 family register 13-2: lcdreg: lcd charge pump control register r/w-0 u-0 rw-1 rw-1 rw-1 rw-1 rw-0 rw-0 cpen ? bias2 bias1 bias0 mode13 clksel1 clksel0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 cpen: 3.6v charge pump enable bit 1 = the regulator generates the highest (3.6v) voltage 0 = highest voltage in the system is supplied externally (v dd ) bit 6 unimplemented: read as ? 0 ? bit 5-3 bias<2:0>: regulator voltage output control bits 111 = 3.60v peak (offset on lcdbias0 of 0v) 110 = 3.47v peak (offset on lcdbias0 of 0.13v) 101 = 3.34v peak (offset on lcdbias0 of 0.26v) 100 = 3.21v peak (offset on lcdbias0 of 0.39v) 011 = 3.08v peak (offset on lcdbias0 of 0.52v) 010 = 2.95v peak (offset on lcdbias0 of 0.65v) 001 = 2.82v peak (offset on lcdbias0 of 0.78v) 000 = 2.69v peak (offset on lcdbias0 of 0.91v) bit 2 mode13: 1/3 lcd bias enable bit 1 = regulator output supports 1/3 lcd bias mode 0 = regulator output supports static lcd bias mode bit 1-0 clksel<1:0> : regulator clock select control bits 11 =lprc 10 =frc 01 =sosc 00 = disable regulator and float regulator voltage output.
pic18f97j94 family ds30575a-page 248 ? 2012 microchip technology inc. register 13-3: lcdps: lcd phase register r/w-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 wft biasmd lcda wa lp3 lp2 lp1 lp0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wft : waveform type select bit 1 = type-b waveform (phase changes on each frame boundary) 0 = type-a waveform (phase changes within each common type) bit 6 biasmd : bias mode select bit when lmux<2:0> = 000 or 011 through 111 : 0 = static bias mode (lmux<2:0> = 000 ) / 1/3 bias mode (lmux<2:0> = 011 through 111 ) (do not set this bit to ? 1 ?) when lmux<2:0> = 001 or 010 : 1 = 1/2 bias mode 0 = 1/3 bias mode bit 5 lcda : lcd active status bit 1 = lcd driver module is active 0 = lcd driver module is inactive bit 4 wa : lcd write allow status bit 1 = writes into the lcddatax registers is allowed 0 = writes into the lcddatax registers is not allowed bit 3-0 lp<3:0> : lcd prescaler select bits 1111 = 1:16 1110 = 1:15 1101 = 1:14 1100 = 1:13 1011 = 1:12 1010 = 1:11 1001 = 1:10 1000 = 1:9 0111 = 1:8 0110 = 1:7 0101 = 1:6 0100 = 1:5 0011 = 1:4 0010 = 1:3 0001 = 1:2 0000 = 1:1
? 2012 microchip technology inc. ds30575a-page 249 pic18f97j94 family 13.2 lcd segment pins configuration the lcdsex registers configure the functions of the port pins. setting the segment enable bit for a particular segment configures that pin as an lcd driver. there are four lcd segment enable registers, as shown in table 13-1 . the prototype lcdsex register is shown in register 13-4 . once the module is initialized for the lcd panel, the individual bits of the lcddatax registers are cleared or set to represent a clear or dark pixel, respectively. specific sets of lcddata registers are used with specific segments and common signals. each bit rep- resents a unique combination of a specific segment connected to a specific common. individual lcddata bits are named by the convention, ?sxxcy?, with ?xx? as the segment number and ?y? as the common number. the relationship is summarized in register 13-3 . the prototype lcddatax register is shown in register 13-5 . register 13-4: lcdsex: lcd segment x enable register table 13-1: lcdsex registers and associated segments register segments lcdse0 seg 7:seg 0 lcdse1 seg 15:seg 8 lcdse2 seg 23:seg 16 lcdse3 seg 31:seg 24 lcdse4 seg 39:seg 32 lcdse5 seg 47:seg 40 lcdse6 seg 55:seg 48 lcdse7 seg 63:seg 56 note: not all lcdsex and lcddatax registers are implemented in lower pin count devices. refer to the specific device data sheet for more details. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 se(n) se(n) se(n) se(n) se(n) se(n) se(n) se(n) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 se(n) : segment enable bits for lcdse0: n = 0-7 for lcdse1: n = 8-15 for lcdse2: n = 16-23 for lcdse3: n = 24-31 for lcdse0: n = 32-39 for lcdse0: n = 40-47 for lcdse0: n = 48-55 for lcdse0: n = 56-63 1 = segment function of the pin is enabled, digital i/o is disabled 0 = segment function of the pin is disabled, digital i/o is enabled
pic18f97j94 family ds30575a-page 250 ? 2012 microchip technology inc. register 13-5: lcddatax: lcd data x register table 13-2: lcddata registers and bits for segment and com combinations r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 s(n)cy s(n)cy s(n)cy s(n)cy s(n)cy s(n)cy s(n)cy s(n)cy bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 s(n)cy: pixel on bits for registers lcddata0 through lcddata7 : n = (0-63), y = 0 for registers lcddata8 through lcddata15 : n = (0-63), y = 1 for registers lcddata16 through lcddata23 : n = (0-63), y = 2 for registers lcddata24 through lcddata31 : n = (0-63), y = 3 for registers lcddata32 through lcddata39 : n = (0-63), y = 4 for registers lcddata40 through lcddata47 : n = (0-63), y = 5 for registers lcddata48 through lcddata55 : n = (0-63), y = 6 for registers lcddata56 through lcddata63 : n = (0-63), y = 7 1 = pixel on 0 = pixel off com lines segments 0 to 7 8 to 15 16 to 23 24 to 31 32 to 39 40 to 47 48 to 55 56 to 63 0 lcddata0 s00c0:s07c0 lcddata1 s08c0:s15c0 lcddata2 s16c0:s23c0 lcddata3 s24c0:s31c0 lcddata4 s32c0:s39c0 lcddata5 s40c0:s47c0 lcddata6 s48c0:s55c0 lcddata7 s56c0:s63c0 1 lcddata8 s00c1:s07c1 lcddata9 s08c1:s15c1 lcddata10 s16c1:s23c1 lcddata11 s24c1:s31c1 lcddata12 s32c1:s39c1 lcddata13 s40c1:s47c1 lcddata14 s48c1:s55c1 lcddata15 s56c1:s63c1 2 lcddata16 s00c2:s07c2 lcddata17 s08c2:s15c2 lcddata18 s16c2:s23c2 lcddata19 s24c2:s31c2 lcddata20 s32c2:s39c2 lcddata21 40c2:s47c2 lcddata22 s48c2:s55c2 lcddata23 s56c2:s63c2 3 lcddata24 s00c3:s07c3 lcddata25 s08c3:s15c3 lcddata26 s16c3:s23c3 lcddata27 s24c3:s31c3 lcddata28 s32c3:s39c3 lcddata29 s40c3:s47c3 lcddata30 s48c3:s55c3 lcddata31 s56c3:s63c3 4 lcddata32 s00c4:s07c4 lcddata33 s08c4:s15c4 lcddata34 s16c4:s23c4 lcddata35 s24c4:s31c4 lcddata36 s32c4:s39c4 lcddata37 s40c4:s47c4 lcddata38 s48c4:s55c4 lcddata39 s56c4:s63c4 5 lcddata40 s00c5:s07c5 lcddata41 s08c5:s15c5 lcddata42 s16c5:s23c5 lcddata43 s24c5:s31c5 lcddata44 s32c5:s39c5 lcddata45 s40c5:s47c5 lcddata46 s48c5:s55c5 lcddata47 s56c5:s63c5 6 lcddata48 s00c6:s07c6 lcddata49 s08c6:s15c6 lcddata50 s16c6:s23c6 lcddata51 s24c6:s31c6 lcddata52 s32c6:s39c6 lcddata53 s40c6:s47c6 lcddata54 s48c6:s55c6 lcddata55 s56c6:s63c6 7 lcddata56 s00c7:s07c7 lcddata57 s08c7:s15c7 lcddata58 s16c7:s23c7 lcddata59 s24c7:s31c7 lcddata60 s32c7:s39c7 lcddata61 s40c7:s47c7 lcddata62 s48c7:s55c7 lcddata63 s56c7:s63c7
? 2012 microchip technology inc. ds30575a-page 251 pic18f97j94 family 13.3 lcd clock source selection the lcd driver module has three possible clock sources: ? frc/8192 ? sosc clock/32 ? lprc/32 the first clock source is the 8 mhz fast internal rc (frc) oscillator divided by 8,192. this divider ratio is chosen to provide about 1 khz output. the divider is not programmable. instead, the lcd prescaler bits, lcdps<3:0>, are used to set the lcd frame clock rate. the second clock source is the sosc oscillator/32. this also outputs about 1 khz when a 32.768 khz crystal is used with the sosc oscillator. to use the sosc oscillator as a clock source, set the soscen (t1con<3>) bit. the third clock source is a 31.25 khz internal lprc oscillator/32 that provides approximately 1 khz output. the second and third clock sources may be used to continue running the lcd while the processor is in sleep. these clock sources are selected through the bits, cs<1:0> (lcdcon<4:3>). 13.3.1 lcd prescaler a 16-bit counter is available as a prescaler for the lcd clock. the prescaler is not directly readable or writable. its value is set by the lp<3:0> bits (lcdps<3:0>) that determine the prescaler assignment and prescale ratio. selectable prescale values are from 1:1 through 1:16, in increments of one. figure 13-2: lcd clock generation cs<1:0> sosc oscillator (32 khz) 4 lmux<2:0> 4-bit prog prescaler 1, 2, 3....8 ring counter lmux<2:0> com0 com1 com2 com7 8192 2 32 32 lp<3:0> (lcdcon<4:2>) (lcdcon<2:0>) (lcdcon<2:0>) (lcdps<3:0>) frc oscillator (8 mh z ) lprc oscillator (31.25 khz) stat 1/2 mux 1/3 to 1/8 mux
pic18f97j94 family ds30575a-page 252 ? 2012 microchip technology inc. 13.4 lcd bias types the lcd module can be configured in one of three bias types: ? static bias (two voltage levels: v ss and v dd ) ? 1/2 bias (three voltage levels: v ss , 1/2 v dd and v dd ) ? 1/3 bias (four voltage levels: v ss , 1/3 v dd , 2/3 v dd and v dd ) lcd bias voltages can be generated with an internal resistor ladders, internal bias generator or external resistor ladder. 13.5 internal resistor biasing this mode does not use external resistors, but rather internal resistor ladders that are configured to generate the bias voltage. the internal reference ladder actually consists of three separate ladders. disabling the internal reference lad- der disconnects all of the ladders, allowing external voltages to be supplied. depending on the total resistance of the resistor ladders, the biasing can be classified as low, medium or high power. table 13-3 shows the total resistance of each of the ladders. tab l e 1 3- 3 shows the internal resister ladder connections. when the internal resistor ladder is selected, the bias voltage can either be from v dd or from v ddcore , depending on the lcdirs setting. it can also provide software contrast control (using lcdcst<2:0>) . table 13-3: internal resi stance ladder power modes power mode nominal resistance of entire ladder i dd low 3 m ? 1 a medium 300 k ? 10 a high 30 k ? 100 a
? 2012 microchip technology inc. ds30575a-page 253 pic18f97j94 family figure 13-3: lcd bias internal resi stor ladder connection diagram there are two power modes, designated as ?mode a? and ?mode b?. mode a is set by the lrlap<1:0> bits and mode b by the lrlb<1:0> bits. the resistor ladder to use for modes a and b are selected by the bits, lrlap<1:0> and lrlbp<1:0>, respectively. each ladder has a matching contrast control ladder, tuned to the nominal resistance of the reference ladder. this contrast control resistor can be controlled by the lcdcst<2:0> bits (lcdrefh<5:3>). disabling the internal reference ladder results in all of the ladders being disconnected, allowing external voltages to be supplied. to get additional current in high-power mode, when lrlap<1:0> (lcdrefl<7:6>) = 11 , both the medium and high-power resistor ladders are activated. whenever the lcd module is inactive, lcda (lcdps<5>) = 0 ), the reference ladder will be turned off. lcdbias3 lcdbias2 lcdbias1 vlcd3pe vlcd2pe vlcd1pe lcdcst<2:0> lcdire lcdirs v dd 3x band gap lrlat<2:0> a power mode b power mode lrlap<1:0> lrlbp<1:0> low resistor ladder medium resistor ladder high resistor ladder v dd v ddcore
pic18f97j94 family ds30575a-page 254 ? 2012 microchip technology inc. 13.5.1 automatic power mode switching as an lcd segment is electrically only a capacitor, cur- rent is drawn only during the interval when the voltage is switching. to minimize total device current, the lcd reference ladder can be operated in a different power mode for the transition portion of the duration. this is controlled by the lcdrefh/l registers. mode a power mode is active for a programmable time, beginning at the time when the lcd segment waveform is transitioning. the lrlat<2:0> bits (lcdrefl<2:0>) select how long or if the mode a is active. mode b power mode is active for the remaining time before the segments or commons change again. as shown in figure 13-4 , there are 32 counts in a single segment time. type-a can be chosen during the time when the wave form is in transition. type-b can be used when the clock is stable or not in transition. by using this feature of automatic power switching using type-a/type-b, the power consumption can be optimized for a given contrast. figure 13-4: lcd reference ladde r power mode switching diagram single segment time 'h00 'h01 'h02 'h03 'h04 'h05 'h06 'h07 'h1e 'h1f 'h00 'h01 'h3 power mode a power mode b mode a lrlat<2:0> lcd_32x_clk cnt<4:0> lcd_clk lrlat<2:0> segment data power mode
? 2012 microchip technology inc. ds30575a-page 255 pic18f97j94 family 13.5.2 contrast control the lcd contrast control circuit consists of a 7-tap resistor ladder, controlled by the lcdcstx bits (see figure 13-5 ) figure 13-5: internal reference and contrast contro l block diagram 13.5.3 internal reference under firmware control, an internal reference for the lcd bias voltages can be enabled. when enabled, the source of this voltage can be v dd . when no internal reference is selected, the lcd con- trast control circuit is disabled and lcd bias must be provided externally. whenever the lcd module is inac- tive (lcda = 0 ), the internal reference will be turned off. 13.5.4 vlcdxpe pins the vlcd3pe, vlcd2pe and vlcd1pe pins provide the ability for an external lcd bias network to be used instead of the internal ladder. use of the vlcdxpe pins does not prevent use of the internal ladder. each vlcdxpe pin has an independent control in the lcdrefh register, allowing access to any or all of the lcd bias signals. this architecture allows for maximum flexibility in differ- ent applications. the vlcdxpe pins could be used to add capacitors to the internal reference ladder for increasing the drive capacity. for applications where the internal contrast control is insufficient, the firmware can choose to enable only the vlcd3pe pin, allowing an external contrast control circuit to use the internal reference divider. lcdcst<2:0> analog rr rr 7 stages mux to to p o f reference ladder 7 0 3 v dd internal reference contrast control
pic18f97j94 family ds30575a-page 256 ? 2012 microchip technology inc. register 13-6: lcdref: lcd refe rence ladder control register r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 lcdire ? lcdcst2 lcdcst1 lcdcst0 vlcd3pe vlcd2pe vlcd1pe bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 lcdire : lcd internal reference enable bit 01 = internal lcd reference is enabled and connected to the internal contrast control circuit 00 = internal lcd reference is disabled bit 6 unimplemented : read as ? 0 ? bit 5-3 lcdcst<2:0> : lcd contrast control bits selects the resistance of the lcd contrast control resistor ladder: 111 = resistor ladder is at maximum resistance (minimum contrast) 110 = resistor ladder is at 6/7th of maximum resistance 101 = resistor ladder is at 5/7th of maximum resistance 100 = resistor ladder is at 4/7th of maximum resistance 011 = resistor ladder is at 3/7th of maximum resistance 010 = resistor ladder is at 2/7th of maximum resistance 001 = resistor ladder is at 1/7th of maximum resistance 000 = minimum resistance (maximum contrast); resistor ladder is shorted bit 2 vlcd3pe : bias3 pin enable bit 01 = bias3 level is connected to the external pin, lcdbias3 00 = bias3 level is internal (internal resistor ladder) bit 1 vlcd2pe : bias2 pin enable bit 01 = bias2 level is connected to the external pin, lcdbias2 00 = bias2 level is internal (internal resistor ladder) bit 0 vlcd1pe : bias1 pin enable bit 01 = bias1 level is connected to the external pin, lcdbias1 00 = bias1 level is internal (internal resistor ladder)
? 2012 microchip technology inc. ds30575a-page 257 pic18f97j94 family register 13-7: lcdrl: lcd reference ladder control register low r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 lrlap1 lrlap0 lrlbp1 lrlbp0 ? lrlat2 lrlat1 lrlat0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 lrlap<1:0> : lcd reference ladder a time power control bits during time interval a: 11 = internal lcd reference ladder is powered in high-power mode 10 = internal lcd reference ladder is powered in medium power mode 01 = internal lcd reference ladder is powered in low-power mode 00 = internal lcd reference ladder is powered down and unconnected bit 5-4 lrlbp<1:0> : lcd reference ladder b time power control bits during time interval b: 11 = internal lcd reference ladder is powered in high-power mode 10 = internal lcd reference ladder is powered in medium power mode 01 = internal lcd reference ladder is powered in low-power mode 00 = internal lcd reference ladder is powered down and unconnected bit 3 unimplemented : read as ? 0 ? bit 2-0 lrlat<2:0> : lcd reference ladder a time interval control bits sets the number of 32 clock counts when the a time interval power mode is active. for type-a waveforms (wft = 0 ): 111 = internal lcd reference ladder is in a power mode for 7 clocks and b power mode for 9 clocks 110 = internal lcd reference ladder is in a power mode for 6 clocks and b power mode for 10 clocks 101 = internal lcd reference ladder is in a power mode for 5 clocks and b power mode for 11 clocks 100 = internal lcd reference ladder is in a power mode for 4 clocks and b power mode for 12 clocks 011 = internal lcd reference ladder is in a power mode for 3 clocks and b power mode for 13 clocks 010 = internal lcd reference ladder is in a power mode for 2 clocks and b power mode for 14 clocks 001 = internal lcd reference ladder is in a power mode for 1 clock and b power mode for 15 clocks 000 = internal lcd reference ladder is always in b power mode for type-b waveforms (wft = 1 ): 111 = internal lcd reference ladder is in a power mode for 7 clocks and b power mode for 25 clocks 110 = internal lcd reference ladder is in a power mode for 6 clocks and b power mode for 26 clocks 101 = internal lcd reference ladder is in a power mode for 5 clocks and b power mode for 27 clocks 100 = internal lcd reference ladder is in a power mode for 4 clocks and b power mode for 28 clocks 011 = internal lcd reference ladder is in a power mode for 3 clocks and b power mode for 29 clocks 010 = internal lcd reference ladder is in a power mode for 2 clocks and b power mode for 30 clocks 001 = internal lcd reference ladder is in a power mode for 1 clock and b power mode for 31 clocks 000 = internal lcd reference ladder is always in b power mode
pic18f97j94 family ds30575a-page 258 ? 2012 microchip technology inc. 13.5.5 lcd bias generation the lcd driver module is capable of generating the required bias voltages for lcd operation with a mini- mum of external components. this includes the ability to generate the different voltage levels required by the different bias types that are required by the lcd. the driver module can also provide bias voltages, both above and below microcontroller v dd , through the use of an on-chip lcd voltage regulator. 13.5.6 lcd bias types pic18f97j94 family devices support three bias types, based on the waveforms generated to control segments and commons: ? static (two discrete levels) ? 1/2 bias (three discrete levels) ? 1/3 bias (four discrete levels) the use of different waveforms in driving the lcd is dis- cussed in more detail in section 13.12 ?lcd waveform generation? . 13.5.7 lcd voltage regulator the purpose of the lcd regulator is to provide proper bias voltage and good contrast for the lcd, regardless of v dd levels. this module contains a charge pump and internal voltage reference. the regulator can be config- ured by using external components to boost bias voltage above v dd . it can also operate a display at a constant voltage below v dd . the regulator can also be selectively disabled to allow bias voltages to be generated by an external resistor network. the lcd regulator is controlled through the lcdreg register. it is enabled or disabled using the clksel<1:0> bits, while the charge pump can be selectively enabled using the cpen bit. when the reg- ulator is enabled, the mode13 bit is used to select the bias type. the peak lcd bias voltage, measured as a difference between the potentials of lcdbias3 and lcdbias0, is configured with the bias bits. register 13-8: lcdreg: lcd voltage regulator control register r/w-0 u-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-0 r/w-0 cpen ? bias2 bias1 bias0 mode13 clksel1 clksel 0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 cpen : lcd charge pump enable bit 1 = charge pump is enabled; highest lcd bias voltage is 3.6v 0 = charge pump is disabled; highest lcd bias voltage is v dd bit 6 unimplemented : read as ? 0 ? bit 5-3 bias<2:0> : regulator voltage output control bits 111 = 3.60v peak (offset on lcdbias0 of 0v) 110 = 3.47v peak (offset on lcdbias0 of 0.13v) 101 = 3.34v peak (offset on lcdbias0 of 0.26v) 100 = 3.21v peak (offset on lcdbias0 of 0.39v) 011 = 3.08v peak (offset on lcdbias0 of 0.52v) 010 = 2.95v peak (offset on lcdbias0 of 0.65v) 001 = 2.82v peak (offset on lcdbias0 of 0.78v) 000 = 2.69v peak (offset on lcdbias0 of 0.91v) bit 2 mode13 : 1/3 lcd bias enable bit 1 = regulator output supports 1/3 lcd bias mode 0 = regulator output supports static lcd bias mode bit 1-0 clksel<1:0> : regulator clock source select bits 11 = 31 khz lprc 10 = 8 mhz frc 01 = sosc 00 = lcd regulator disabled
? 2012 microchip technology inc. ds30575a-page 259 pic18f97j94 family 13.6 bias configurations pic18f97j94 family devices have four distinct circuit configurations for lcd bias generation: ? m0: regulator with boost ? m1: regulator without boost ? m2: resistor ladder with software contrast ? m3: resistor ladder with hardware contrast 13.6.1 m0 (regulator with boost) in m0 operation, the lcd charge pump feature is enabled. this allows the regulator to generate voltages up to +3.6v to the lcd (as measured at lcdbias3). m0 uses a flyback capacitor connected between v lcap 1 and v lcap 2, as well as filter capacitors on lcdbias0 through lcdbias3, to obtain the required voltage boost ( figure 13-6 ). the output voltage (v bias ) is the difference of the potential between lcdbias3 and lcdbias0. it is set by the bias<2:0> bits which adjust the offset between lcdbias0 and v ss . the flyback capacitor (c fly ) acts as a charge storage ele- ment for large lcd loads. this mode is useful in those cases where the voltage requirements of the lcd are higher than the microcontroller?s v dd . it also permits software control of the display?s contrast, by adjust- ment of bias voltage, by changing the value of the bias bits. m0 supports static and 1/3 bias types. generation of the voltage levels for 1/3 bias is handled automatically, but must be configured in software. m0 is enabled by selecting a valid regulator clock source (clksel<1:0> set to any value except ? 00 ?) and setting the cpen bit. if static bias type is required, the mode13 bit must be cleared. 13.6.2 m1 (regulator without boost) m1 operation is similar to m0, but does not use the lcd charge pump. it can provide v bias up to the voltage level supplied directly to lcdbias3. it can be used in cases where v dd for the application is expected to never drop below a level that can provide adequate contrast for the lcd. the connection of external com- ponents is very similar to m0, except that lcdbias3 must be tied directly to v dd ( figure 13-6 ). the bias<2:0> bits can still be used to adjust contrast in software by changing the v bias . as with m0, chang- ing these bits changes the offset between lcdbias0 and v ss . in m1, this is reflected in the change between the lcdbias0 and the voltage tied to lcdbias3. thus, if v dd should change, v bias will also change; where in m0, the level of v bias is constant. like m0, m1 supports static and 1/3 bias types. generation of the voltage levels for 1/3 bias is handled automatically but must be configured in software. m1 is enabled by selecting a valid regulator clock source (clksel<1:0> set to any value except ? 00 ?) and clear- ing the cpen bit. if 1/3 bias type is required, the mode13 bit should also be set. note: when the device is put to sleep while oper- ating in mode m0 or m1, make sure that the bias capacitors are fully discharged to get the lowest sleep current.
pic18f97j94 family ds30575a-page 260 ? 2012 microchip technology inc. figure 13-6: lcd regulator connectio ns for m0 and m1 configurations lcdbias3 lcdbias2 lcdbias1 lcdbias0 v lcap 1 v lcap 2 c0 c1 c2 c3 c0 c1 c2 v dd mode 0 (v bias up to 3.6v) mode 1 (v bias ? v dd ) c fly note 1: these values are provided for design guidance only; they should be optimized for the application by the designer based on the actual lcd specifications. 0.47 ? f (1) 0.47 ? f (1) 0.47 ? f (1) 0.47 ? f (1) 0.47 ? f (1) 0.47 ? f (1) 0.47 ? f (1) 0.47 ? f (1) 0.47 ? f (1) pic18f97j94
? 2012 microchip technology inc. ds30575a-page 261 pic18f97j94 family 13.6.3 m2 (external resistor ladder with software contrast) m2 operation also uses the lcd regulator but disables the charge pump. the regulator?s internal voltage refer- ence remains active as a way to regulate contrast. it is used in cases where the current requirements of the lcd exceed the capacity of the regulator?s charge pump. in this configuration, the lcd bias voltage levels are created by an external resistor voltage divider, connected across lcdbias0 through lcdbias3, with the top of the divider tied to v dd ( figure 13-7 ). the potential at the bottom of the ladder is determined by the lcd regulator?s voltage reference, tied internally to lcdbias0. the bias type is determined by the volt- ages on the lcdbias pins, which are controlled by the configuration of the resistor ladder. most applications, using m2, will use a 1/3 or 1/2 bias type. while static bias can also be used, it offers extremely limited con- trast range and additional current consumption over other bias generation modes. like m1, the lcdbias bits can be used to control con- trast, limited by the level of v dd supplied to the device. also, since there is no capacitor required across v lcap 1 and v lcap 2, these pins are available as digital i/o ports, rg2 and rg3. m2 is selected by clearing the clksel<1:0> bits and setting the cpen bit. figure 13-7: resistor ladder conne ctions for m2 configuration lcdbias3 note 1: these values are provided for design guidance only; they should be optimized for the application by the designer based on the actual lcd specifications. bias level at pin bias type 1/2 bias 1/3 bias lcdbias0 (internal low reference voltage) (internal low reference voltage) lcdbias1 1/2 v bias 1/3 v bias lcdbias2 1/2 v bias 2/3 v bias lcdbias3 v bias (up to v dd )v bias (up to v dd ) 10 k ? (1) 10 k ? (1) 1/2 bias 1/3 bias lcdbias2 lcdbias1 lcdbias0 10 k ? (1) 10 k ? (1) 10 k ? (1) v dd v dd v dd v dd v dd v dd pic18f97j94
pic18f97j94 family ds30575a-page 262 ? 2012 microchip technology inc. 13.6.4 m3 (hardware contrast) in m3, the lcd regulator is completely disabled. like m2, lcd bias levels are tied to v dd and are generated using an external divider. the difference is that the internal voltage reference is also disabled and the bot- tom of the ladder is tied to ground (v ss ); see figure 13- 8 . the value of the resistors, and the difference between v ss and v dd , determine the contrast range; no software adjustment is possible. this configuration is also used where the lcd?s current requirements exceed the capacity of the charge pump and software contrast control is not needed. depending on the bias type required, resistors are con- nected between some or all of the pins. a potentiome- ter can also be connected between lcdbias3 and v dd to allow for hardware controlled contrast adjust- ment. m3 is selected by clearing the clksel<1:0> and cpen bits. figure 13-8: resistor ladder co nnections for m3 configuration lcdbias3 note 1: these values are provided for design guidance only; they should be optimized for the application by the designer based on the actual lcd specifications. 2: a potentiometer for manual contrast adjustment is optional; it may be omitted entirely. bias level at pin bias type static 1/2 bias 1/3 bias lcdbias0 av ss av ss av ss lcdbias1 av ss 1/2 v dd 1/3 v dd lcdbias2 v dd 1/2 v dd 2/3 v dd lcdbias3 v dd v dd v dd 10 k ? (1) 10 k ? (1) static bias 1/2 bias 1/3 bias lcdbias2 lcdbias1 lcdbias0 10 k ? (1) 10 k ? (1) 10 k ? (1) v dd (2) v dd v dd pic18f97j94
? 2012 microchip technology inc. ds30575a-page 263 pic18f97j94 family 13.7 design considerations for the lcd charge pump when designing applications that use the lcd regula- tor with the charge pump enabled, users must always consider both the dynamic current and rms (static) current requirements of the display, and what the charge pump can deliver. both dynamic and static current can be determined by equation 13-1 : equation 13-1: lcd static, dynamic current for dynamic current, c , is the value of the capacitors attached to lcdbias3 and lcdbias2. the variable, dv , is the voltage drop allowed on c2 and c3 during a voltage switch on the lcd display, and dt is the duration of the transient current after a clock pulse occurs. for practical design purposes, it will be assumed to be 0.047 f for c , 0.1v for dv and 1 s for dt . this yields a dynamic current of 4.7 ma for 1 s. rms current is determined by the value of c fly for c , the voltage across v lcap 1 and v lcap 2 for dv and the regulator clock period (tper) for dt . assuming a c fly value of 0.047 f, a value of 1.02v across c fly and tper of 30 s, the maximum theoretical static current will be 1.8 ma. since the charge pump must charge five capacitors, the maximum current becomes 360 a. for a real-world assumption of 50% efficiency, this yields a practical current of 180 a. users should com- pare the calculated current capacity against the requirements of the lcd. while dv and dt are relatively fixed by device design, the values of c fly and the capacitors on the lcdbias pins can be changed to increase or decrease current. as always, any changes should be evaluated in the actual circuit for their impact on the application. i = c x dv dt
pic18f97j94 family ds30575a-page 264 ? 2012 microchip technology inc. 13.8 lcd multiplex types the lcd driver module can be configured into four multiplex types: ? static (only com0 used) ? 1/2 multiplex (com0 and com1 are used) ? 1/3 multiplex (com0, com1 and com2 are used) ? 1/4 multiplex (com0, com1, com2 and com3 are used) ? 1/5 multiplex (com0, com1, com2, com3 and com4 are used) ? 1/6 multiplex (com0, com1, com2, com3, com4 and com5 are used) ? 1/7 multiplex (com0, com1, com2, com3, com4, com5 and com6 are used) ? 1/8 multiplex (com0, com1, com2, com3, com4, com5, com6 and com7 are used) the lmux<2:0> setting (lcdcon<2:0>) decides the function of the com pins. (for details, see ta bl e 1 3 - 4 ). if the pin is a digital i/o, the corresponding tris bit controls the data direction. if the pin is a com drive, the tris setting of that pin is overridden. 13.9 segment enables the lcdsex registers are used to select the pin function for each segment pin. the selection allows each pin to operate as either an lcd segment driver or a digital only pin. to configure the pin as a segment pin, the corre- sponding bits in the lcdsex registers must be set to ? 1 ?. if the pin is a digital i/o, the corresponding tris bit controls the data direction. any bit set in the lcdsex registers overrides any bit settings in the corresponding tris register. 13.10 pixel control the lcddatax registers contain bits that define the state of each pixel. each bit defines one unique pixel. table 13-2 shows the correlation of each bit in the lcddatax registers to the respective common and segment signals. any lcd pixel location not being used for display can be used as general purpose ram. 13.11 lcd frame frequency the rate at which the com and seg outputs change is called the lcd frame frequency. note: on a power-on reset, the lmux<2:0> bits are ? 000 ?. table 13-4: com<7:0> pin functions lmux<2:0> com7 pin com6 pin com5 pin com4 pin com3 pin com2 pin com1 pin com0 pin 111 com7 com6 com5 com4 com3 com2 com1 com0 110 i/o pin com6 com5 com4 com3 com2 com1 com0 101 i/o pin i/o pin com5 com4 com3 com2 com1 com0 100 i/o pin i/o pin i/o pin com4 com3 com2 com1 com0 011 i/o pin i/o pin i/o pin i/o pin com3 com2 com1 com0 010 i/o pin i/o pin i/o pin i/o pin i/o pin com2 com1 com0 001 i/o pin i/o pin i/o pin i/o pin i/o pin i/o pin com1 com0 000 i/o pin i/o pin i/o pin i/o pin i/o pin i/o pin i/o pin com0 note: pins, com<7:4>, can also be used as seg pins when ? multiplex to static multiplex are used. these pins can be used as i/o pins only if respective bits in the lcdsex registers are set to ? 0 ?. note: on a power-on reset, these pins are configured as digital i/o. table 13-5: frame frequency formulas multiplex frame frequency = static (? 000 ?) clock source/(4 x 1 x (lp<3:0> + 1)) 1/2 (? 001 ?) clock source/(2 x 2 x (lp<3:0> + 1)) 1/3 (? 010 ?) clock source/(1 x 3 x (lp<3:0> + 1)) 1/4 (? 011 ?) clock source/(1 x 4 x (lp<3:0> + 1)) 1/5 (? 100 ?) clock source/(1 x 5 x (lp<3:0> + 1)) 1/6 (? 101 ?) clock source/(1 x 6 x (lp<3:0> + 1)) 1/7 (? 110 ?) clock source/(1 x 7 x (lp<3:0> + 1)) 1/8 (? 111 ?) clock source/(1 x 8 x (lp<3:0> + 1)) note: the clock source is frc/8192, sosc/32 or lprc/32.
? 2012 microchip technology inc. ds30575a-page 265 pic18f97j94 family 13.12 lcd waveform generation lcd waveform generation is based on the philosophy that the net ac voltage across the dark pixel should be maximized and the net ac voltage across the clear pixel should be minimized. the net dc voltage across any pixel should be zero. the com signal represents the time slice for each common, while the seg contains the pixel data. the pixel signal (com-seg) will have no dc compo- nent and can take only one of the two rms values. the higher rms value will create a dark pixel and a lower rms value will create a clear pixel. as the number of commons increases, the delta between the two rms values decreases. the delta rep- resents the maximum contrast that the display can have. the lcds can be driven by two types of waveforms: type-a and type-b. in a type-a waveform, the phase changes within each common type, whereas a type-b waveform?s phase changes on each frame boundary. thus, type-a waveforms maintain 0 vdc over a single frame, whereas type-b waveforms take two frames. figure 13-9 through figure 13-21 provide waveforms for static, half-multiplex, one-third multiplex and quarter multiplex drives for type-a and type-b waveforms. figure 13-9: type-a/type-b waveforms in static drive note: if sleep has to be executed with lcd sleep enabled (slpen (lcdcon<6>) = 1 ), care must be taken to execute sleep only when vdc on all the pixels is ? 0 ?. v 1 v 0 com0 seg0 com0-seg0 com0-seg1 seg1 v 1 v 0 v 1 v 0 v 0 v 1 -v 1 v 0 1 frame com0 seg0 seg1 seg2 seg3 seg4 seg5 seg6 seg7
pic18f97j94 family ds30575a-page 266 ? 2012 microchip technology inc. figure 13-10: type-a waveforms in 1/2 mux, 1/2 bias drive v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 -v 2 -v 1 v 2 v 1 v 0 -v 2 -v 1 com0 com1 seg0 seg1 com0-seg0 com0-seg1 1 frame com1 com0 seg0 seg1 seg2 seg3
? 2012 microchip technology inc. ds30575a-page 267 pic18f97j94 family figure 13-11: type-b waveforms in 1/2 mux, 1/2 bias drive v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 -v 2 -v 1 v 2 v 1 v 0 -v 2 -v 1 com0 com1 seg0 seg1 com0-seg0 com0-seg1 com1 com0 seg0 seg1 seg2 seg3 2 frames
pic18f97j94 family ds30575a-page 268 ? 2012 microchip technology inc. figure 13-12: type-a waveforms in 1/2 mux, 1/3 bias drive v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 com0 com1 seg0 seg1 com0-seg0 com0-seg1 1 frame com1 com0 seg0 seg1 seg2 seg3
? 2012 microchip technology inc. ds30575a-page 269 pic18f97j94 family figure 13-13: type-b waveforms in 1/2 mux, 1/3 bias drive v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 com0 com1 seg0 seg1 com0-seg0 com0-seg1 com1 com0 seg0 seg1 seg2 seg3 2 frames
pic18f97j94 family ds30575a-page 270 ? 2012 microchip technology inc. figure 13-14: type-a waveforms in 1/3 mux, 1/2 bias drive v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 -v 2 -v 1 v 2 v 1 v 0 -v 2 -v 1 com0 com1 com2 seg0 seg1 com0-seg0 com0-seg1 1 frame com2 com1 com0 seg0 seg1 seg2 seg2
? 2012 microchip technology inc. ds30575a-page 271 pic18f97j94 family figure 13-15: type-b waveforms in 1/3 mux, 1/2 bias drive v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 -v 2 -v 1 v 2 v 1 v 0 -v 2 -v 1 com0 com1 com2 seg0 seg1 com0-seg0 com0-seg1 2 frames com2 com1 com0 seg0 seg1 seg2
pic18f97j94 family ds30575a-page 272 ? 2012 microchip technology inc. figure 13-16: type-a waveforms in 1/3 mux, 1/3 bias drive v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 com0 com1 com2 seg0 seg1 com0-seg0 com0-seg1 1 frame com2 com1 com0 seg0 seg1 seg2 seg2
? 2012 microchip technology inc. ds30575a-page 273 pic18f97j94 family figure 13-17: type-b waveforms in 1/3 mux, 1/3 bias drive v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 com0 com1 com2 seg0 seg1 com0-seg0 com0-seg1 2 frames com2 com1 com0 seg0 seg1 seg2
pic18f97j94 family ds30575a-page 274 ? 2012 microchip technology inc. figure 13-18: type-a waveforms in 1/4 mux, 1/3 bias drive v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 com0 com1 com2 com3 seg0 seg1 com0-seg0 com0-seg1 com3 com2 com1 com0 1 frame seg0 seg1
? 2012 microchip technology inc. ds30575a-page 275 pic18f97j94 family figure 13-19: type-b waveforms in 1/4 mux, 1/3 bias drive v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 com0 com1 com2 com3 seg0 seg1 com0-seg0 com0-seg1 com3 com2 com1 com0 2 frames seg0 seg1
pic18f97j94 family ds30575a-page 276 ? 2012 microchip technology inc. figure 13-20: type-a waveforms in 1/8 mux, 1/3 bias drive com4 com3 com2 com1 seg0 com5 com7 com6 com0 com0 com1 com2 com7 seg0 com0-seg0 com1-seg0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0
? 2012 microchip technology inc. ds30575a-page 277 pic18f97j94 family figure 13-21: type-b waveforms in 1/8 mux, 1/3 bias drive com4 com3 com2 com1 seg0 com5 com7 com6 com0 v3 v2 com0 v1 v0 v3 v2 v1 com1 v0 v3 v2 v1 com2 v0 v3 v2 v1 com7 v0 v3 v2 seg0 v1 v0 v3 v2 v1 v0 com0 - seg0 -v1 -v2 -v3 v3 v2 v1 v0 com1 - seg0 -v1 -v2 -v3
pic18f97j94 family ds30575a-page 278 ? 2012 microchip technology inc. 13.13 lcd interrupts the lcd timing generation provides an interrupt that defines the lcd frame timing. this interrupt can be used to coordinate the writing of the pixel data with the start of a new frame, which produces a visually crisp transition of the image. this interrupt can also be used to synchronize external events to the lcd. for example, the interface to an external segment driver can be synchronized for segment data updates to the lcd frame. a new frame is defined as beginning at the leading edge of the com0 common signal. the interrupt will be set immediately after the lcd controller completes accessing all pixel data required for a frame. this will occur at a fixed interval before the frame boundary (t fint ), as shown in figure 13-22 . the lcd controller will begin to access data for the next frame within the interval from the interrupt to when the controller begins accessing data after the interrupt (t fwr ). new data must be written within t fwr , as this is when the lcd controller will begin to access the data for the next frame. when the lcd driver is running with type-b wave- forms, and the lmux<2:0> bits are not equal to ? 000 ?, there are some additional issues. since the dc voltage on the pixel takes two frames to maintain 0v, the pixel data must not change between subsequent frames. if the pixel data were allowed to change, the waveform for the odd frames would not necessarily be the complement of the waveform gener- ated in the even frames and a dc component would be introduced into the panel. because of this, using type-b waveforms requires synchronizing the lcd pixel updates to occur within a subframe after the frame interrupt. to correctly sequence writing in type-b, the interrupt only occurs on complete phase intervals. if the user attempts to write when the write is disabled, the werr bit (lcdcon<5>) is set. figure 13-22: example waveforms and interrupt timing in quarter duty cycle drive note: the interrupt is not generated when the type-a waveform is selected and when the type-b with no multiplex (static) is selected. frame boundary frame boundary lcd interrupt occurs controller accesses next frame data t fint t fwr t fwr =t frame /2 * (lmux<2:0> + 1) + t cy /2 t fint =(t fwr /2 ? (2 t cy + 40 ns)) ?? minimum = 1.5(t frame /4) ? (2 t cy + 40 ns) (t fwr /2 ? (1 t cy + 40 ns)) ?? maximum = 1.5(t frame /4) ? (1 t cy + 40 ns) frame boundary v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 com0 com1 com2 com3 2 frames
? 2012 microchip technology inc. ds30575a-page 279 pic18f97j94 family 13.14 configuring the lcd module to configure the lcd module. 1. select the frame clock prescale using bits, lp<3:0> (lcdps<3:0>). 2. configure the appropriate pins to function as segment drivers using the lcdsex registers. 3. if using the internal reference resistors for biasing, enable the internal reference ladder and: ? define the mode a and mode b interval by using the lrlat<2:0> bits (lcdrefl<2:0>) ? define the low, medium or high ladder for mode a and mode b by using the lrlap<1:0> bits (lcdrefl<7:6>) and the lrlbp<1:0> bits (lcdrefl<5:4>), respectively ? set the vlcdxpe bits and enable the lcdire bit (lcdrefh<7>) 4. configure the following lcd module functions using the lcdconl register: ? multiplex and bias mode ? lmux<2:0> bits ? timing source ? cs<1:0> bits ? sleep mode ? slpen bit 5. write initial values to the pixel data registers, lcddata0 through lcddata63. 6. clear the lcd interrupt flag, lcdif, and if desired, enable the interrupt by setting bit, lcdie. 7. enable the lcd module by setting the on bit (lcdconl<7>) 13.15 operation during sleep the lcd module can operate during sleep. the selec- tion is controlled by the slpen bit (lcdconl<6>). setting the slpen bit allows the lcd module to go to sleep. clearing the slpen bit allows the module to continue to operate during sleep. if a sleep instruction is executed and slpen = 1 , the lcd module will cease all functions and go into a very low-current consumption mode. the module will stop operation immediately and drive the minimum lcd volt- age on both segment and common lines. figure 13-23 shows this operation. the lcd module current consumption will not decrease in this mode, but the overall consumption of the device will be lower due to shut down of the core and other peripheral functions. to ensure that no dc component is introduced on the panel, the sleep instruction should be executed imme- diately after an lcd frame boundary. the lcd interrupt can be used to determine the frame boundary. see section 13.13 ?lcd interrupts? for the formulas to calculate the delay. if a sleep instruction is executed and slpen = 0 , the module will continue to display the current contents of the lcddata registers. the lcd data cannot be changed.
pic18f97j94 family ds30575a-page 280 ? 2012 microchip technology inc. figure 13-23: sleep entry/exit when slpen = 1 or cs<1:0> = 00 . sleep instruction execution wake-up 2 frames v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 com0 com1 com2 seg0
? 2012 microchip technology inc. ds30575a-page 281 pic18f97j94 family 14.0 timer0 module the timer0 module incorporates the following features: ? software-selectable operation as a timer or counter in both 8-bit or 16-bit modes ? readable and writable registers ? dedicated 8-bit, software programmable prescaler ? selectable clock source (internal or external) ? edge select for external clock ? interrupt-on-overflow the t0con register ( register 14-1 ) controls all aspects of the module?s operation, including the prescale selection. it is both readable and writable. figure 14-1 provides a simplified block diagram of the timer0 module in 8-bit mode. figure 14-2 provides a simplified block diagram of the timer0 module in 16-bit mode. register 14-1: t0con: ti mer0 control register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 tmr0on t08bit t0cs1 t0cs0 psa t0ps2 t0ps1 t0ps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr0on: timer0 on/off control bit 1 = enables timer0 0 = stops timer0 bit 6 t08bit : timer0 8-bit/16-bit control bit 1 = timer0 is configured as an 8-bit timer/counter 0 = timer0 is configured as a 16-bit timer/counter bit 5-4 t0cs<1:0> : timer0 clock source select bit 11 = increment on high-to-low transition on t0cki pin 10 = increment on low-to-high transition on t0cki pin 01 = internal clock (f osc /4) 00 = intosc bit 3 psa : timer0 prescaler assignment bit 1 = timer0 prescaler is not assigned; timer0 clock input bypasses prescaler 0 = timer0 prescaler is assigned; timer0 clock input comes from prescaler output bit 2-0 t0ps<2:0> : timer0 prescaler select bits 111 = 1:256 prescale value 110 = 1:128 prescale value 101 = 1:64 prescale value 100 = 1:32 prescale value 011 = 1:16 prescale value 010 = 1:8 prescale value 001 = 1:4 prescale value 000 = 1:2 prescale value
pic18f97j94 family ds30575a-page 282 ? 2012 microchip technology inc. 14.1 timer0 operation timer0 can operate in one of these two modes: ? as an 8-bit (t08bit = 1 ) or 16-bit (t08bit = 0 ) timer ? as an asynchronous 8-bit (t08bit = 1 ) or 16-bit (t08bit = 0 ) counter 14.1.1 timer mode in timer mode, timer0 either increments every cpu clock cycle, or every instruction cycle, depending on the clock select bit, tmr0cs<1:0> (t0con<7:6>). 14.1.2 counter mode in this mode, timer0 is incremented via a rising or fall- ing edge of an external source on the t0cki pin. the clock select bits, tmr0cs<1:0>, must be set to ? 1x ?. 14.2 timer0 reads and writes in 16-bit mode tmr0h is not the actual high byte of timer0 in 16-bit mode. it is actually a buffered version of the real high byte of timer0, which is not directly readable nor writable (see figure 14-2 ). tmr0h is updated with the contents of the high byte of timer0 during a read of tmr0l. this provides the ability to read all 16 bits of timer0 without having to verify that the read of the high and low byte were valid, due to a rollover between successive reads of the high and low byte. similarly, a write to the high byte of timer0 must also take place through the tmr0h buffer register. the high byte is updated with the contents of tmr0h when a write occurs to tmr0l. this allows all 16 bits of timer0 to be updated at once. figure 14-1: timer0 block diagram (8-bit mode) figure 14-2: timer0 block di agram (16-bit mode) note: upon reset, timer0 is enabled in 8-bit mode wit h clock input from t0cki max. prescale. t0cki pin t0se 0 1 1 0 t0cs f osc /4 sync with internal clocks tmr0l (2 t cy delay) internal data bus psa t0ps<2:0> set tmr0if on overflow 3 8 8 programmable prescaler note: upon reset, timer0 is enabled in 8-bit mode with clock input from t0cki max. prescale. t0cki pin t0se 0 1 1 0 t0cs f osc /4 sync with internal clocks tmr0l (2 t cy delay) internal data bus 8 psa t0ps<2:0> set tmr0if on overflow 3 tmr0 tmr0h high byte 8 8 8 read tmr0l write tmr0l 8 programmable prescaler
? 2012 microchip technology inc. ds30575a-page 283 pic18f97j94 family 14.3 prescaler an 8-bit counter is available as a prescaler for the timer0 module. the prescaler is not directly readable or writable. its value is set by the psa and t0ps<2:0> bits (t0con<3:0>), which determine the prescaler assignment and prescale ratio. clearing the psa bit assigns the prescaler to the timer0 module. when it is assigned, prescale values from 1:2 through 1:256 in power-of-two increments are selectable. when assigned to the timer0 module, all instructions writing to the tmr0 register (for example, clrf tmr0 , movwf tmr0 , bsf tmr0 ) clear the prescaler count. 14.3.1 switching prescaler assignment the prescaler assignment is fully under software control and can be changed ?on-the-fly? during program execution. 14.4 timer0 interrupt the tmr0 interrupt is generated when the tmr0 register overflows from ffh to 00h in 8-bit mode, or from ffffh to 0000h in 16-bit mode. this overflow sets the tmr0if flag bit. the interrupt can be masked by clearing the tmr0ie bit (intcon<5>). before re- enabling the interrupt, the tmr0if bit must be cleared in software by the interrupt service routine (isr). since timer0 is shutdown in sleep mode, the tmr0 interrupt cannot awaken the processor from sleep. note: writing to tmr0 when the prescaler is assigned to timer0 will clear the prescaler count but will not change the prescaler assignment.
pic18f97j94 family ds30575a-page 284 ? 2012 microchip technology inc. 15.0 timer1/3/5 modules the timer1/3/5 timer/counter modules incorporate these features: ? software-selectable operation as a 16-bit timer or counter ? readable and writable eight-bit registers (tmrxh and tmrxl) ? selectable clock source (internal or external) with device clock or sosc oscillator internal options ? interrupt-on-overflow ? module reset on eccp special event trigger a simplified block diagram of the timer1/3/5 module is shown in figure 15-1 . the timer1/3/5 module is controlled through the txcon register ( register 15-1 ). it also selects the clock source options for the eccp modules. (for more information, see section 18.1.1 ?eccp module and timer resources? ). the f osc clock source should not be used with the eccp capture/compare features. if the timer will be used with the capture or compare features, always select one of the other timer clocking options. note: throughout this section, generic references are used for register and bit names that are the same ? except for an ?x? variable that indicates the item?s association with the timer1, timer3 or timer5 module. for example, the control register is named txcon and refers to t1con, t3con and t5con.
? 2012 microchip technology inc. ds30575a-page 285 pic18f97j94 family register 15-1: txcon: ti merx control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 tmrxcs1 tmrxcs0 txckps1 txckps0 soscen txsync rd16 tmrxon bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 tmrxcs<1:0>: timerx clock source select bits 11 = timerx clock source is intosc 10 = timerx clock source depends on the soscen bit: soscen = 0 : external clock from the txcki pin (on the rising edge). soscen = 1 : depending on the soscsel fuses, either a crystal oscillator on the sosci/sosco pins or an external clock from the sclki pin. 01 = timerx clock source is the system clock (f osc ) ( 1 ) 00 = timerx clock source is the instruction clock (f osc /4) bit 5-4 txckps<1:0> : timerx input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 soscen : sosc oscillator enable bit 1 = sosc/sclki are enabled for timerx (based on the soscsel fuses) 0 = sosc/sclki are disabled for timerx and txcki is enabled bit 2 txsync : timerx external clock input synchronization control bit (not usable if the device clock comes from timer1/3/5.) when tmrxcs<1:0> = 10 : 1 = do not synchronize external clock input 0 = synchronize external clock input when tmrxcs<1:0> = 0x : this bit is ignored; timer1/3/5 uses the internal clock. bit 1 rd16: 16-bit read/write mode enable bit 1 = enables register read/write of timerx in one 16-bit operation 0 = enables register read/write of timerx in two eight-bit operations bit 0 tmrxon: timerx on bit 1 = enables timerx 0 = stops timerx note 1: the f osc clock source should not be selected if the timer will be used with the eccp capture/compare features.
pic18f97j94 family ds30575a-page 286 ? 2012 microchip technology inc. 15.1 timer1/3/5 gate control register the timer1/3/5 gate control register (txgcon), provided in register 15-2 , is used to control the timerx gate. register 15-2: txgcon: timerx gate control register ( 1 ) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-x r/w-0 r/w-0 tmrxge txgpol txgtm txgspm txggo/txdone txgval txgss1 txgss0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmrxge: timerx gate enable bit if tmrxon = 0 : this bit is ignored. if tmrxon = 1 : 1 = timerx counting is controlled by the timerx gate function 0 = timerx counts regardless of timerx gate function bit 6 txgpol: timerx gate polarity bit 1 = timerx gate is active-high (timerx counts when gate is high) 0 = timerx gate is active-low (timerx counts when gate is low) bit 5 txgtm: timerx gate toggle mode bit 1 = timerx gate toggle mode is enabled. 0 = timerx gate toggle mode is disabled and toggle flip-flop is cleared timerx gate flip-flop toggles on every rising edge. bit 4 txgspm: timerx gate single pulse mode bit 1 = timerx gate single pulse mode is enabled and is controlling timerx gate 0 = timerx gate single pulse mode is disabled bit 3 txggo/txdone : timerx gate single pulse acquisition status bit 1 = timerx gate single pulse acquisition is ready, waiting for an edge 0 = timerx gate single pulse acquisition has completed or has not been started this bit is automatically cleared when txgspm is cleared. bit 2 txgval: timerx gate current state bit indicates the current state of the timerx gate that could be provided to tmrxh:tmrxl; unaffected by the timerx gate enable (tmrxge) bit. bit 1-0 txgss<1:0>: timerx gate source select bits 11 = comparator 2 output 10 = comparator 1 output 01 = tmr(x+1) to match pr(x+1) output ( 2 ) 00 = timer1 gate pin the watchdog timer oscillator is turned on if tmrxge = 1 , regardless of the state of tmrxon. note 1: programming the txgcon prior to txcon is recommended. 2: timer(x+1) will be timer1/3/5 for timerx (timer1/3/5), respectively.
? 2012 microchip technology inc. ds30575a-page 287 pic18f97j94 family 15.2 timer1/3/5 operation timer1, timer3 and timer5 can operate in these modes: ?timer ? synchronous counter ? asynchronous counter ? timer with gated control the operating mode is determined by the clock select bits, tmrxcsx (txcon<7:6>). when the tmrxcsx bits are cleared (= 00 ), timer1/3/5 increments on every inter- nal instruction cycle (f osc /4). when tmrxcsx = 01 , the timer1/3/5 clock source is the system clock (f osc ). when it is ? 10 ?, timer1/3/5 works as a counter from the external clock from the txcki pin (on the rising edge after the first falling edge) or the sosc oscillator. when it is ? 11 ?, the timer1/3/5 clock source is intosc. figure 15-1: timer1/3/5 block diagram tmr3h tmr3l t3sync t3ckps<1:0> 0 1 synchronized clock input 2 set flag bit tmr3if on overflow tmr3 (2) tmr3on note 1: st buffer is a high-speed type when using t3cki. 2: timer3 registers increment on the rising edge. 3: synchronization does not operate while in sleep. 4: the output of sosc is determined by the soscsel configuration bits. t3g sosc f osc /4 internal clock sosco/sclki sosci 1 0 t3cki tmr3cs<1:0> (1) synchronize (3) det sleep input tmr3ge 0 1 00 01 10 11 from tmr4 t3gpol d q ck q 0 1 t3gval t3gtm t3gspm t3ggo/ t3gss<1:0> en out (4) 10 00 01 f osc internal clock from comparator 2 match pr4 r q1 rd t3gcon data bus interrupt tmr3gif set t3clk f osc /2 internal clock d en q t3g_in tmr3on output 01 timer3 clock is intosc single pulse acq. control t3done prescaler 1, 2, 4, 8 from comparator 1 output t1con.soscen t1con.soscen soscgo nosc<2:0> = 100 d en q det
pic18f97j94 family ds30575a-page 288 ? 2012 microchip technology inc. 15.3 timer1/3/5 16-bit read/write mode timer1/3/5 can be configured for 16-bit reads and writes (see figure 15-3 ). when the rd16 control bit (txcon<1>) is set, the address for tmrxh is mapped to a buffer register for the high byte of timer1/3/5. a read from tmrxl will load the contents of the high byte of timer1/3/5 into the timerx high byte buffer register. this provides users with the ability to accurately read all 16 bits of timer1/3/5 without having to determine whether a read of the high byte, followed by a read of the low byte, has become invalid due to a rollover between reads. a write to the high byte of timer1/3/5 must also take place through the tmrxh buffer register. the timer1/3/5 high byte is updated with the contents of tmrxh when a write occurs to tmrxl. this allows users to write all 16 bits to both the high and low bytes of timer1/3/5 at once. the high byte of timer1/3/5 is not directly readable or writable in this mode. all reads and writes must take place through the timerx high byte buffer register. writes to tmrxh do not clear the timer1/3/5 prescaler. the prescaler is only cleared on writes to tmrxl. 15.4 using the sosc oscillator as the timer1/3/5 clock source the sosc internal oscillator may be used as the clock source for timer1/3/5. it can be enabled in one of these ways: ? setting the soscen bit in either of the txcon registers (txcon<3>) ? setting the soscgo bit in the osccon2 register (osccon2<1>) ? setting the nosc bits to secondary clock source in the osccon register (osccon<2:0> = 100 ) the soscgo bit is used to warm up the sosc so that it is ready before any peripheral requests it. to use it as the timer3 clock source, the tmr3csx bits must also be set. as previously noted, this also config- ures timer3 to increment on every rising edge of the oscillator source. the sosc oscillator is described in section 15.4 ?using the sosc oscillator as the timer1/3/5 clock source? .
? 2012 microchip technology inc. ds30575a-page 289 pic18f97j94 family 15.5 timer1/3/5 gates timer1/3/5 can be configured to count freely or the count can be enabled and disabled using the timer1/3/5 gate circuitry. this is also referred to as the timer1/3/5 gate count enable. the timer1/3/5 gate can also be driven by multiple selectable sources. 15.5.1 timer1/3/5 gate count enable the timerx gate enable mode is enabled by setting the tmrxge bit (txgcon<7>). the polarity of the timerx gate enable mode is configured using the txgpol bit (txgcon<6>). when timerx gate enable mode is enabled, timer1/3/5 will increment on the rising edge of the timer1/3/5 clock source. when timerx gate enable mode is disabled, no incrementing will occur and timer1/3/5 will hold the current count. see figure 15-2 for timing details. table 15-1: timer1/3/5 gate enable selections figure 15-2: timer1/3/5 gate count enable mode txclk ( ? ) txgpol (txgcon<6>) txg pin timerx operation ? 00 counts ? 01 holds count ? 10 holds count ? 11 counts ? the clock on which tmr1/3/5 is running. for more information, see txclk in figure 15-1 . tmrxge txgpol txg_in txcki txgval timer1/3/5 n n + 1 n + 2 n + 3 n + 4
pic18f97j94 family ds30575a-page 290 ? 2012 microchip technology inc. 15.5.2 timer1/3/5 gate source selection the timer1/3/5 gate source can be selected from one of four different sources. source selection is controlled by the txgss<1:0> bits (txgcon<1:0>). the polarity for each available source is also selectable and is controlled by the txgpol bit (txgcon <6>). table 15-2: timer1/3/5 gate sources 15.5.2.1 txg pin gate operation the txg pin is one source for timer1/3/5 gate control. it can be used to supply an external source to the timerx gate circuitry. 15.5.2.2 timer2/4/6/8 match gate operation the tmr(x+1) register will increment until it matches the value in the pr(x+1) register. on the very next increment cycle, tmr2 will be reset to 00h. when this reset occurs, a low-to-high pulse will automatically be gener- ated and internally supplied to the timerx gate circuitry. the pulse will remain high for one instruction cycle and will return back to a low state until the next match. depending on txgpol, timerx increments differently when tmr(x+1) matches pr(x+1). when txgpol = 1 , timerx increments for a single instruction cycle following a tmr(x+1) match with pr(x+1). when txgpol = 0 , timerx increments continuously, except for the cycle following the match, when the gate signal goes from low-to-high. 15.5.2.3 comparator 1 output gate operation the output of comparator1 can be internally supplied to the timerx gate circuitry. after setting up comparator 1 with the cm1con register, timerx will increment depending on the transitions of the c1out (cmstat<0>) bit. 15.5.2.4 comparator 2 output gate operation the output of comparator 2 can be internally supplied to the timerx gate circuitry. after setting up comparator 2 with the cm2con register, timerx will increment depending on the transitions of the c2out (cmstat<1>) bit. 15.5.3 timer1/3/5 gate toggle mode when timer1/3/5 gate toggle mode is enabled, it is pos- sible to measure the full cycle length of a timer1/3/5 gate signal, as opposed to the duration of a single level pulse. the timerx gate source is routed through a flip-flop that changes state on every incrementing edge of the signal. (for timing details, see figure 15-3 .) the txgval bit will indicate when the toggled mode is active and the timer is counting. timer1/3/5 gate toggle mode is enabled by setting the txgtm bit (txgcon<5>). when the txgtm bit is cleared, the flip-flop is cleared and held clear. this is necessary in order to control which edge is measured. figure 15-3: timer1/3/5 gate toggle mode txgss<1:0> timerx gate source 00 timerx gate pin 01 tmr(x+1) to match pr(x+1) (tmr(x+1) increments to match pr(x+1)) 10 comparator 1 output (comparator logic high output) 11 comparator 2 output (comparator logic high output) tmrxge txgpol txgtm txg_in txcki txgval timer1/3/5 n n + 1 n + 2 n + 3 n + 4 n + 5 n + 6 n + 7 n + 8
? 2012 microchip technology inc. ds30575a-page 291 pic18f97j94 family 15.5.4 timer1/3/5 gate single pulse mode when timer1/3/5 gate single pulse mode is enabled, it is possible to capture a single pulse gate event. timer1/3/5 gate single pulse mode is first enabled by setting the txgspm bit (txgcon<4>). next, the txggo/txdone bit (txgcon<3>) must be set. the timer1/3/5 will be fully enabled on the next incre- menting edge. on the next trailing edge of the pulse, the txggo/txdone bit will automatically be cleared. no other gate events will be allowed to increment timer1/3/5 until the txggo/txdone bit is once again set in software. clearing the txgspm bit also will clear the txggo/ txdone bit. (for timing details, see figure 15-4 .) simultaneously enabling the toggle mode and the single pulse mode will permit both sections to work together. this allows the cycle times on the timer1/3/5 gate source to be measured. (for timing details, see figure 15-5 .) figure 15-4: timer1/3/5 gate single pulse mode tmrxge txgpol txg_in txcki txgval timer1/3/5 n n + 1 n + 2 txgspm txggo/ txdone set by software cleared by hardware on falling edge of txgval set by hardware on falling edge of txgval cleared by software cleared by software tmrxgif counting enabled on rising edge of txg
pic18f97j94 family ds30575a-page 292 ? 2012 microchip technology inc. figure 15-5: timer1/3/5 gate single pulse and toggle combined mode 15.5.5 timer1/3/5 gate value status when timer1/3/5 gate value status is utilized, it is possible to read the most current level of the gate con- trol value. the value is stored in the txgval bit (txgcon<2>). the txgval bit is valid even when the timer1/3/5 gate is not enabled (tmrxge bit is cleared). 15.5.6 timer1/3/5 gate event interrupt when the timer1/3/5 gate event interrupt is enabled, it is possible to generate an interrupt upon the comple- tion of a gate event. when the falling edge of txgval occurs, the tmrxgif flag bit in the pirx register will be set. if the tmrxgie bit in the piex register is set, then an interrupt will be recognized. the tmrxgif flag bit operates even when the timer1/3/5 gate is not enabled (tmrxge bit is cleared). tmrxge txgpol txg_in txcki txgval timer1/3/5 n n + 1 n + 2 txgspm txggo/ txdone set by software cleared by hardware on falling edge of txgval set by hardware on falling edge of txgval cleared by software cleared by software tmrxgif txgtm counting enabled on rising edge of txg n + 4 n + 3
? 2012 microchip technology inc. ds30575a-page 293 pic18f97j94 family 15.6 timer1/3/5 interrupt the tmrx register pair (tmrxh:tmrxl) increments from 0000h to ffffh and overflows to 0000h. the timerx interrupt, if enabled, is generated on overflow and is latched in the interrupt flag bit, tmrxif. table 15-3 gives each module?s flag bit. this interrupt can be enabled or disabled by setting or clearing the tmrxie bit, respectively. table 15-4 gives each module?s enable bit. 15.7 resetting timer1/3/5 using the eccp special event trigger if the eccp modules are configured to use timerx and to generate a special event trigger in compare mode (ccpxm<3:0> = 1011 ), this signal will reset timerx. the trigger from eccp2 will also start an a/d conversion if the a/d module is enabled (for more information, see section 18.3.4 ?special event trigger? .) the module must be configured as either a timer or synchronous counter to take advantage of this feature. when used this way, the ccprxh:ccprxl register pair effectively becomes a period register for timerx. if timerx is running in asynchronous counter mode, the reset operation may not work. in the event that a write to timerx coincides with a special event trigger from an eccp module, the write will take precedence. table 15-3: timer1/3/5 interrupt flag bits timer module flag bit 1 pir1<0> 3 pir2<1> 5 pir5<1> table 15-4: timer1/3/5 interrupt enable bits timer module flag bit 1 pie1<0> 3 pie2<1> 5 pie5<1> note: the special event triggers from the eccpx module will only clear the tmr3 register?s content, but not set the tmr3if interrupt flag bit (pir1<0>). note: the ccp and eccp modules use timers, 1 through 8, for some modes. the assign- ment of a particular timer to a ccp/eccp module is determined by the timer to ccp enable bits in the ccptmrsx registers. for more details, see register 18-2 , register 18-3 and register 19-2
pic18f97j94 family ds30575a-page 294 ? 2012 microchip technology inc. 16.0 timer2/4/6/8 modules the timer2/4/6/8 timer modules have the following features: ? eight-bit timer register (tmrx) ? eight-bit period register (prx) ? readable and writable (all registers) ? software programmable prescaler (1:1, 1:4, 1:16) ? software programmable postscaler (1:1 to 1:16) ? interrupt on tmrx match of prx the timer2/4/6/8 modules have a control register, shown in register 16-1 . timer2/4/6/8 can be shut off by clearing control bit, tmrxon (txcon<2>), to minimize power consumption. the prescaler and postscaler selection of timer2/4/6/8 also are controlled by this register. figure 16-1 is a simplified block diagram of the timer2/4/6/8 modules. 16.1 timer2/4/6/8 operation timer2/4/6/8 can be used as the pwm time base for the pwm mode of the eccp modules. the tmrx reg- isters are readable and writable, and are cleared on any device reset. the input clock (f osc /4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits, txckps<1:0> (txcon<1:0>). the match output of tmrx goes through a four-bit postscaler (that gives a 1:1 to 1:16 inclusive scaling) to generate a tmrx interrupt, latched in the flag bit, tmrxif. tab l e 1 6- 1 gives each module?s flag bit. the interrupt can be enabled or disabled by setting or clearing the timerx interrupt enable bit (tmrxie), shown in tab l e 1 6- 2 . the prescaler and postscaler counters are cleared when any of the following occurs: ? a write to the tmrx register ? a write to the txcon register ? any device reset ? power-on reset (por), mclr reset, watchdog timer reset (wdtr) or brown-out reset (bor) a tmrx is not cleared when a txcon is written. note: throughout this section, generic references are used for register and bit names that are the same, except for an ?x? variable that indicates the item?s association with the timer2, timer4, timer6 or timer8 module. for example, the control register is named txcon and refers to t2con, t4con, t6con and t8con. table 16-1: timer2/4/6/8 flag bits timer module flag bit 2pir1<1> 4pir5<0> 6pir5<2> 8pir5<4> table 16-2: timer2/4/6/8 interrupt enable bits timer module flag bit 2pie1<1> 4pie5<0> 6pie5<2> 8pie5<4> note: the ccp and eccp modules use timers, 1 through 8, for some modes. the assign- ment of a particular timer to a ccp/eccp module is determined by the timer to ccp enable bits in the ccptmrsx registers. for more details, see register 18-2 , register 18-3 and register 19-2 .
? 2012 microchip technology inc. ds30575a-page 295 pic18f97j94 family 16.2 timer2/4/6/8 interrupt the timer2/4/6/8 modules have eight-bit period registers, prx, that are both readable and writable. timer2/4/6/8 increment from 00h until they match pr2/ 4/6/8 and then reset to 00h on the next increment cycle. the prx registers are initialized to ffh upon reset. 16.3 output of tmrx the outputs of tmrx (before the postscaler) are used only as a pwm time base for the eccp modules. they are not used as baud rate clocks for the msspx modules as is the timer2 output. figure 16-1: timer2/4/6/8 block diagram register 16-1: txcon: timerx co ntrol register (timer2/4/6/8) u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? txoutps3 txoutps2 txoutps1 txoutps0 tmrxon txckps1 txckps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-3 txoutps<3:0>: timerx output postscale select bits 0000 = 1:1 postscale 0001 = 1:2 postscale ? ? ? 1111 = 1:16 postscale bit 2 tmrxon : timerx on bit 1 = timerx is on 0 = timerx is off bit 1-0 txckps<1:0>: timerx clock prescale select bits 00 = prescaler is 1 01 = prescaler is 4 1x = prescaler is 16 comparator tmrx output tmrx postscaler prescaler prx 2 f osc /4 1:1 to 1:16 1:1, 1:4, 1:16 4 txoutps<3:0> txckps<1:0> set tmrxif internal data bus 8 reset tmrx/prx 8 8 (to pwm) match
pic18f97j94 family ds30575a-page 296 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 297 pic18f97j94 family 17.0 real-time clock and calendar (rtcc) the key features of the real-time clock and calendar (rtcc) module are: ? hardware real-time clock and calendar (rtcc) ? provides hours, minutes and seconds using 24- hour format ? visibility of one-half second period ? provides calendar ? weekday, date, month and year ? alarm configurable for half a second, one second, 10 seconds, one minute, 10 minutes, one hour, one day, one week or one month ? alarm repeat with decrementing counter ? alarm with indefinite repeat ? chime ? year 2000 to 2099 leap year correction ? bcd format for smaller software overhead ? optimized for long term battery operation ? fractional second synchronization ? multiple clock sources -sosc -lprc -50 hz -60 hz ? user calibration of the 32.768 khz clock crystal frequency with periodic auto-adjust ? calibration to within 2.64 seconds error per month ? calibrates up to 260 ppm of crystal error the rtcc module is intended for applications where accurate time must be maintained for an extended period with minimum to no intervention from the cpu. the module is optimized for low-power usage in order to provide extended battery life, while keeping track of time. the module is a 100-year clock and calendar with auto- matic leap year detection. the range of the clock is from 00:00:00 (midnight) on january 1, 2000 to 23:59:59 on december 31, 2099. hours are measured in 24-hour (military time) format. the clock provides a granularity of one second with half-second visibility to the user. figure 17-1: rtcc block diagram rtcc prescalers rtcc timer comparator compare registers repeat counter year mthdy wkdyhr minsec almthdy alwdhr alminsec with masks rtcc interrupt logic rtccon1 alrmrpt alarm event 0.5s rtcc clock domain alarm pulse rtcc interrupt cpu clock domain rtcvalx alrmvalx rtcc pin rtcoe 32.768 khz input from sosc oscillator internal rc (lf-intosc)
pic18f97j94 family ds30575a-page 298 ? 2012 microchip technology inc. 17.1 rtcc module registers the rtcc module registers are divided into the following categories: rtcc control registers ? rtccon1 ? rtccon2 ? rtccal ? padcfg ?alrmcfg ?alrmrpt rtcc value registers ?rtcvalh ?rtcvall both registers access the following registers: - year -month -day - weekday -hour - minute - second alarm value registers ?alrmvalh ? alrmvall both registers access the following registers: - alrmmnth -alrmday -alrmwd -alrmhr - alrmmin - alrmsec note: the rtcvalh and rtcvall registers can be accessed through rtcrpt<1:0> (rtccon1<1:0>). alrmvalh and alrmvall can be accessed through alrmptr<1:0> (alrmcfg<1:0>).
? 2012 microchip technology inc. ds30575a-page 299 pic18f97j94 family 17.1.1 rtcc control registers register 17-1: rtccon1: rtcc configuration register 1 ( 1 ) r/w-0 u-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 rtcen ( 2 ) ?rtcwren ( 4 ) rtcsync halfsec ( 3 ) rtcoe rtcptr1 rtcptr0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rtcen: rtcc enable bit ( 2 ) 1 = rtcc module is enabled 0 = rtcc module is disabled bit 6 unimplemented: read as ? 0 ? bit 5 rtcwren: rtcc value registers write enable bit ( 4 ) 1 = rtcvalh, rtcvall and rtccon2 registers can be written to by the user 0 = rtcvalh, rtcvall and rtccon2 registers are locked out from being written to by the user bit 4 rtcsync: rtcc value registers read synchronization bit 1 = rtcvalh, rtcvall and alrmrpt registers can change while reading if a rollover ripple results in an invalid data read. if the register is read twice and results in the same data, the data can be assumed to be valid. 0 = rtcvalh, rtcvall or alrmrpt registers can be read without concern over a rollover ripple bit 3 halfsec: half-second status bit ( 3 ) 1 = second half period of a second 0 = first half period of a second bit 2 rtcoe: rtcc output enable bit 1 = rtcc clock output is enabled 0 = rtcc clock output is disabled bit 1-0 rtcptr<1:0>: rtcc value register window pointer bits points to the corresponding rtcc value registers when reading the rtcvalh and rtcvall registers. the rtcptr<1:0> value decrements on every read or write of rtcvalh<15:8> until it reaches ? 00 ?. rtcvalh: 00 = minutes 01 = weekday 10 = month 11 = reserved rtcvall: 00 = seconds 01 = hours 10 = day 11 = year note 1: the rtccon1 register is only affected by a por. 2: a write to the rtcen bit is only allowed when rtcwren = 1 . 3: this bit is read-only; it is cleared to ? 0 ? on a write to the lower half of the minsec register. 4: rtcwren can only be written with the unlock sequence (see example 17-1 ).
pic18f97j94 family ds30575a-page 300 ? 2012 microchip technology inc. register 17-2: rtccal: rtcc calibration register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 cal7 cal6 cal5 cal4 cal3 cal2 cal1 cal0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 cal<7:0>: rtc drift calibration bits 01111111 = maximum positive adjustment; adds 508 rtc clock pulses every minute . . . 00000001 = minimum positive adjustment; adds four rtc clock pulses every minute 00000000 = no adjustment 11111111 = minimum negative adjustment; subtracts four rtc clock pulses every minute . . . 10000000 = maximum negative adjustment; subtracts 512 rtc clock pulses every minute
? 2012 microchip technology inc. ds30575a-page 301 pic18f97j94 family register 17-3: rtccon2: rtc configuration register 2 ( 1 ) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pwcen ( 1 ) pwcpol ( 1 ) pwccpre ( 1 ) pwcspre ( 1 ) rtcclksel1 rtcclksel0 rtcsecsel1 rtcsecsel0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pwcen: power control enable bit ( 1 ) 1 = power control is enabled 0 = power control is disabled bit 6 pwcpol: power control polarity bit ( 1 ) 1 = power control output is active-high 0 = power control output is active-low bit 5 pwccpre: power control/stability prescaler bits ( 1 ) 1 = pwc stability window clock is divide-by-2 of source rtcc clock 0 = pwc stability window clock is divide-by-1 of source rtcc clock bit 4 pwcspre: power control sample prescaler bits ( 1 ) 01 = pwc sample window clock is divide-by-2 of source rtcc clock 00 = pwc sample window clock is divide-by-1 of source rtcc clock bit 3-2 rtcclksel<1:0>: rtcc clock select bits determines the source of the internal rtcc clock, which is used for all rtcc timer operations. 11 = 60 hz powerline 10 = 50 hz powerline 01 =intosc 00 =sosc bit 1-0 rtsecsel<1:0>: rtcc seconds clock output select bit 11 = power control 10 = rtcc source clock is selected for the rtcc pin (pin can be lf-intosc or sosc, depending on the rtcosc (config3l<1>) bit setting 01 = rtcc seconds clock is selected for the rtcc pin 00 = rtcc alarm pulse is selected for the rtcc pin note 1: the rtccon2 register is only affected by a por.
pic18f97j94 family ds30575a-page 302 ? 2012 microchip technology inc. register 17-4: alrmcfg: al arm configuration register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 alrmen chime amask3 amask2 amask1 amask0 alrmptr1 alrmptr0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 alrmen: alarm enable bit 1 = alarm is enabled (cleared automatically after an alarm event whenever arpt<7:0> = 00h and chime = 0 ) 0 = alarm is disabled bit 6 chime: chime enable bit 1 = chime is enabled; arpt<7:0> bits are allowed to roll over from 00h to ffh 0 = chime is disabled; arpt<7:0> bits stop once they reach 00h bit 5-2 amask<3:0>: alarm mask configuration bits 0000 = every half second 0001 = every second 0010 = every 10 seconds 0011 = every minute 0100 = every 10 minutes 0101 = every hour 0110 = once a day 0111 = once a week 1000 = once a month 1001 = once a year (except when configured for february 29 th , once every four years) 101x = reserved ? do not use 11xx = reserved ? do not use bit 1-0 alrmptr<1:0>: alarm value register window pointer bits points to the corresponding alarm value registers when reading the alrmvalh and alrmvall registers. the alrmptr<1:0> value decrements on every read or write of alrmvalh until it reaches ? 00 ?. alrmvalh: 00 = alrmmin 01 =alrmwd 10 =alrmmnth 11 = unimplemented alrmvall: 00 = alrmsec 01 =alrmhr 10 =alrmday 11 = unimplemented
? 2012 microchip technology inc. ds30575a-page 303 pic18f97j94 family 17.1.2 rtcvalh and rtcvall register mappings the registers described in this section are the targets or sources for writes or reads to the rtcvalh and rtcvall in the order they will appear when accessed through the rtccon1 pointer. for more information on rtcval register mapping, please see section 17.2.8 ?register mapping? . register 17-5: alrmrpt: alarm repeat register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 arpt7 arpt6 arpt5 arpt4 arpt3 arpt2 arpt1 arpt0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 arpt<7:0>: alarm repeat counter value bits 11111111 = alarm will repeat 255 more times . . . 00000000 = alarm will not repeat the counter decrements on any alarm event. the counter is prevented from rolling over from 00h to ffh unless chime = 1 . register 17-6: reserved register (rtcvalh when rtcptr<1:0> = 11 ) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 unimplemented: read as ? 0 ? note: a read or write to the rtcvalh register when rtcptr<1:0> = 11 is necessary to automatically decrement rtcptr.
pic18f97j94 family ds30575a-page 304 ? 2012 microchip technology inc. register 17-7: year: year value register ( 1 ) (rtcvall when rtcptr<1:0> = 11 ) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x yrten3 yrten2 yrten1 yrten0 yrone3 yrone2 yrone1 yrone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 yrten<3:0>: binary coded decimal value of year?s tens digit bits contains a value from 0 to 9. bit 3-0 yrone<3:0>: binary coded decimal value of year?s ones digit bits contains a value from 0 to 9. note 1: a write to the year register is only allowed when rtcwren = 1 . register 17-8: month: month value register ( 1 ) (rtcvalh when rtcptr<1:0> = 10 ) u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ? mthten0 mthone3 mthone2 mthone1 mthone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 mthten0: binary coded decimal value of month?s tens digit bit contains a value of 0 or 1. bit 3-0 mthone<3:0>: binary coded decimal value of month?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 .
? 2012 microchip technology inc. ds30575a-page 305 pic18f97j94 family register 17-9: day: day value register ( 1 ) (rtcvall when rtcptr<1:0> = 10 ) u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? dayten1 dayten0 dayone3 dayone2 dayone1 dayone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 dayten<1:0>: binary coded decimal value of day?s tens digit bits contains a value from 0 to 3. bit 3-0 dayone<3:0>: binary coded decimal value of day?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 . register 17-10: weekday: weekday value register ( 1 ) (rtcvalh when rtcptr<1:0> = 01 ) u-0 u-0 u-0 u-0 u-0 r/w-x r/w-x r/w-x ? ? ? ? ? wday2 wday1 wday0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-3 unimplemented: read as ? 0 ? bit 2-0 wday<2:0>: binary coded decimal value of weekday digit bits contains a value from 0 to 6. note 1: a write to this register is only allowed when rtcwren = 1 . register 17-11: hour: hour value register ( 1 ) (rtcvall when rtcptr<1:0> = 01 ) u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? hrten1 hrten0 hrone3 hrone2 hrone1 hrone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 hrten<1:0>: binary coded decimal value of hour?s tens digit bits contains a value from 0 to 2. bit 3-0 hrone<3:0>: binary coded decimal value of hour?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 .
pic18f97j94 family ds30575a-page 306 ? 2012 microchip technology inc. register 17-12: minute: minute value re gister (rtcvalh when rtcptr<1:0> = 00 ) u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? minten2 minten1 minten0 minone3 minone2 minone1 minone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-4 minten<2:0>: binary coded decimal value of minute?s tens digit bits contains a value from 0 to 5. bit 3-0 minone<3:0>: binary coded decimal value of minute?s ones digit bits contains a value from 0 to 9. register 17-13: second: second value re gister (rtcvall when rtcptr<1:0> = 00 ) u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? secten2 secten1 secten0 secone3 secone2 secone1 secone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-4 secten<2:0>: binary coded decimal value of second?s tens digit bits contains a value from 0 to 5. bit 3-0 secone<3:0>: binary coded decimal value of second?s ones digit bits contains a value from 0 to 9.
? 2012 microchip technology inc. ds30575a-page 307 pic18f97j94 family 17.1.3 alrmvalh and alrmvall register mappings the registers described in this section are the targets or sources for writes or reads to the alrmvalh and alrmvall in the order they will appear when accessed through the alrmcfg pointer. for more information on alrmval register mapping, please see section 17.2.8 ?register mapping? . register 17-14: alrmmnth: alarm month value register ( 1 ) (alrmvalh when alrmptr<1:0> = 10 ) u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ? mthten0 mthone3 mthone2 mthone1 mthone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 mthten0: binary coded decimal value of month?s tens digit bits contains a value of 0 or 1. bit 3-0 mthone<3:0>: binary coded decimal value of month?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 . register 17-15: alrmday: alarm day value register ( 1 ) (alrmvall when alrmptr<1:0> = 10 ) u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? dayten1 dayten0 dayone3 dayone2 dayone1 dayone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 dayten<1:0>: binary coded decimal value of day?s tens digit bits contains a value from 0 to 3. bit 3-0 dayone<3:0>: binary coded decimal value of day?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 .
pic18f97j94 family ds30575a-page 308 ? 2012 microchip technology inc. register 17-16: alrmwd: alarm weekday value register ( 1 ) (alrmvalh when alrmptr<1:0> = 01 ) u-0 u-0 u-0 u-0 u-0 r/w-x r/w-x r/w-x ? ? ? ? ? wday2 wday1 wday0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-3 unimplemented: read as ? 0 ? bit 2-0 wday<2:0>: binary coded decimal value of weekday digit bits contains a value from 0 to 6. note 1: a write to this register is only allowed when rtcwren = 1 . register 17-17: alrmhr: alarm hours value register ( 1 ) (alrmvall when alrmptr<1:0> = 01 ) u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? hrten1 hrten0 hrone3 hrone2 hrone1 hrone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 hrten<1:0>: binary coded decimal value of hour?s tens digit bits contains a value from 0 to 2. bit 3-0 hrone<3:0>: binary coded decimal value of hour?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 .
? 2012 microchip technology inc. ds30575a-page 309 pic18f97j94 family register 17-18: alrmmin: alarm minutes value register (alrmvalh when alrmptr<1:0> = 00 ) u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? minten2 minten1 minten0 minone3 minone2 minone1 minone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-4 minten<2:0>: binary coded decimal value of minute?s tens digit bits contains a value from 0 to 5. bit 3-0 minone<3:0>: binary coded decimal value of minute?s ones digit bits contains a value from 0 to 9. register 17-19: alrmsec: alarm seconds value register (alrmvall when alrmptr<1:0> = 00 ) u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? secten2 secten1 secten0 secone3 secone2 secone1 secone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-4 secten<2:0>: binary coded decimal value of second?s tens digit bits contains a value from 0 to 5. bit 3-0 secone<3:0>: binary coded decimal value of second?s ones digit bits contains a value from 0 to 9.
pic18f97j94 family ds30575a-page 310 ? 2012 microchip technology inc. 17.1.4 rtcen bit write rtcwren (rtccon1<5>) must be set before a write to rtcen can take place. any write to the rtcen bit, while rtcwren = 0 , will be ignored. like the rtcen bit, the rtcvalh and rtcvall registers can only be written to when rtcwren = 1 . a write to these registers, while rtcwren = 0 , will be ignored. 17.2 operation 17.2.1 register interface the register interface for the rtcc and alarm values is implemented using the binary coded decimal (bcd) format. this simplifies the firmware when using the module, as each of the digits is contained within its own 4-bit value (see figure 17-2 and figure 17-3 ). figure 17-2: timer digit format figure 17-3: alarm digit format 0-6 0-9 0-9 0-3 0-9 0-9 0-9 0-9 0-2 0-5 0-5 0/1 day of week year day hours (24-hour format) minutes seconds 1/2 second bit 0-1 0-9 month (binary format) 0-6 0-3 0-9 0-9 0-9 0-9 0-2 0-5 0-5 day of week day hours (24-hour format) minutes seconds 0-1 0-9 month
? 2012 microchip technology inc. ds30575a-page 311 pic18f97j94 family 17.2.2 clock source as mentioned earlier, the rtcc module is intended to be clocked by an external real-time clock (rtc) crys- tal, oscillating at 32.768 khz, but an internal oscillator can be used. the rtcc clock selection is decided by the rtcosc bit (config3l<0>). calibration of the crystal can be done through this module to yield an error of 3 seconds or less per month. (for further details, see section 17.2.9 ?calibration? .) figure 17-4: clock source multiplexing 17.2.2.1 real-time clock enable the rtcc module can be clocked by an external, 32.768 khz crystal (sosc oscillator) or the lf-intosc oscillator, which can be selected in config3l<0>. if the external clock is used, the sosc oscillator should be enabled. if lf-intosc is providing the clock, the intosc clock can be brought out to the rtcc pin by the rtsecsel<1:0> bits (rtccon2<1:0>). 17.2.3 digit carry rules this section explains which timer values are affected when there is a rollover: ? time of day: from 23:59:59 to 00:00:00 with a carry to the day field ? month: from 12/31 to 01/01 with a carry to the year field ? day of week: from 6 to 0 with no carry (see table 17-1 ) ? year carry: from 99 to 00; this also surpasses the use of the rtcc for the day-to-month rollover schedule, see table 17-2 . because the following values are in bcd format, the carry to the upper bcd digit occurs at the count of 10, not 16 (seconds, minutes, hours, weekday, days and months). table 17-1: day of week schedule table 17-2: day to month rollover schedule note 1: writing to the lower half of the minsec register resets all counters, allowing fraction of a second synchronization; clock prescaler is held in reset when rtcen = 0 . 32.768 khz xtal 1:16384 half second (1) half-second clock one second clock year month day day of week second hour:minute clock prescaler (1) from sosc internal rc rtccon1 day of week sunday 0 monday 1 tuesday 2 wednesday 3 thursday 4 friday 5 saturday 6 month maximum day field 01 (january) 31 02 (february) 28 or 29 ( 1 ) 03 (march) 31 04 (april) 30 05 (may) 31 06 (june) 30 07 (july) 31 08 (august) 31 09 (september) 30 10 (october) 31 11 (november) 30 12 (december) 31 note 1: see section 17.2.4 ?leap year? .
pic18f97j94 family ds30575a-page 312 ? 2012 microchip technology inc. 17.2.4 leap year since the year range on the rtcc module is 2000 to 2099, the leap year calculation is determined by any year divisible by four in the above range. only february is affected in a leap year. february will have 29 days in a leap year and 28 days in any other year. 17.2.5 general functionality all timer registers containing a time value of seconds or greater are writable. the us er configures the time by writing the required year, month, day, hour, minutes and seconds to the timer registers, via register pointers. (see section 17.2.8 ?register mapping? .) the timer uses the newly written values and proceeds with the count from the required starting point. the rtcc is enabled by setting the rtcen bit (rtccon1<7>). if enabled, while adjusting these registers, the timer still continues to increment. however, any time the minsec register is written to, both of the timer prescalers are reset to ? 0 ?. this allows fraction of a second synchronization. the timer registers are updated in the same cycle as the write instruction?s execution by the cpu. the user must ensure that when rtcen = 1 , the updated registers will not be incremented at the same time. this can be accomplished in several ways: ? by checking the rtcsync bit (rtccon1<4>) ? by checking the preceding digits from which a carry can occur ? by updating the registers immediately following the seconds pulse (or an alarm interrupt) the user has visibility to the half-second field of the counter. this value is read-only and can be reset only by writing to the lower half of the seconds register. 17.2.6 safety window for register reads and writes the rtcsync bit indicates a time window during which the rtcc clock domain registers can be safely read and written without concern about a rollover. when rtcsync = 0 , the registers can be safely accessed by the cpu. whether rtcsync = 1 or 0 , the user should employ a firmware solution to ensure that the data read did not fall on a rollover boundary, resulting in an invalid or partial read. this firmware solution would consist of reading each register twice and then comparing the two values. if the two values matched, then a rollover did not occur. 17.2.7 write lock in order to perform a write to any of the rtcc timer registers, the rtcwren bit (rtccon1<5>) must be set. to avoid accidental writes to the rtcc timer register, it is recommended that the rtcwren bit (rtccon1<5>) be kept clear when not writing to the register. for the rtcwren bit to be set, there is only one instruction cycle time window allowed between the 55h/aa sequence and the setting of rtcwren. for that reason, it is recommended that users follow the code example in example 17-1 . example 17-1: setting the rtcwren bit 17.2.8 register mapping to limit the register interface, the rtcc timer and alarm timer registers are accessed through corresponding register pointers. the rtcc value register window (rtcvalh and rtcvall) uses the rtcptrx bits (rtccon1<1:0>) to select the required timer register pair. by reading or writing to the rtcvalh register, the rtcc pointer value (rtcptr<1:0>) decrements by ? 1 ? until it reaches ? 00 ?. when ? 00 ? is reached, the minutes and seconds value is accessible through rtcvalh and rtcvall until the pointer value is manually changed. table 17-3: rtcvalh and rtcvall register mapping the alarm value register windows (alrmvalh and alrmvall) use the alrmptr bits (alrmcfg<1:0>) to select the desired alarm register pair. by reading or writing to the alrmvalh register, the alarm pointer value, alrmptr<1:0>, decrements by ? 1 ? until it reaches ? 00 ?. when it reaches ? 00 ?, the alrmmin and alrmsec values are accessible through alrmvalh and alrmvall until the pointer value is manually changed. movlw 0x55 movwf eecon2 movlw 0xaa movwf eecon2 bsf rtccon1,rtcwren rtcptr<1:0> rtcc value register window rtcvalh rtcvall 00 minutes seconds 01 weekday hours 10 month day 11 ? year
? 2012 microchip technology inc. ds30575a-page 313 pic18f97j94 family table 17-4: alrmval register mapping 17.2.9 calibration the real-time crystal input can be calibrated using the periodic auto-adjust feature. when properly calibrated, the rtcc can provide an error of less than three seconds per month. to perform this calibration, find the number of error clock pulses and store the value into the lower half of the rtccal register. the 8-bit signed value, loaded into rtccal, is multiplied by four and will either be added or subtracted from the rtcc timer, once every minute. to calibrate the rtcc module: 1. use another timer resource on the device to find the error of the 32.768 khz crystal. 2. convert the number of error clock pulses per minute (see equation 17-1 ). ? if the oscillator is faster than ideal (negative result from step 2), the rcfgcall register value needs to be negative. this causes the specified number of clock pulses to be subtracted from the timer counter once every minute. ? if the oscillator is slower than ideal (positive result from step 2), the rcfgcall register value needs to be positive. this causes the specified number of clock pulses to be added to the timer counter once every minute. 3. load the rtccal register with the correct value. writes to the rtccal register should occur only when the timer is turned off or immediately after the rising edge of the seconds pulse. 17.3 alarm the alarm features and characteristics are: ? configurable from half a second to one year ? enabled using the alrmen bit (alrmcfg<7>, register 17-4 ) ? offers one-time and repeat alarm options 17.3.1 configuring the alarm the alarm feature is enabled using the alrmen bit. this bit is cleared when an alarm is issued. the bit will not be cleared if the chime bit = 1 or if alrmrpt ? 0 . the interval selection of the alarm is configured through the alrmcfg bits (amask<3:0>); see figure 17-5 . these bits determine which and how many digits of the alarm must match the clock value for the alarm to occur. the alarm can also be configured to repeat based on a preconfigured interval. the number of times this occurs, after the alarm is enabled, is stored in the alrmrpt register. alrmptr<1:0> alarm value register window alrmvalh alrmvall 00 alrmmin alrmsec 01 alrmwd alrmhr 10 alrmmnth alrmday 11 ?? equation 17-1: converting error clock pulses (ideal frequency (32,758) ? measured frequency) * 60 = error clocks per minute note: in determining the crystal?s error value, it is the user?s responsibility to include the crystal?s initial error from drift due to temperature or crystal aging. note: while the alarm is enabled (alrmen = 1 ), changing any of the registers, other than the rtccal, alrmcfg and alrmrpt registers and the chime bit, can result in a false alarm event leading to a false alarm interrupt. to avoid this, only change the timer and alarm values while the alarm is disabled (alrmen = 0 ). it is recommended that the alrmcfg and alrmrpt registers and chime bit be changed when rtcsync = 0 .
pic18f97j94 family ds30575a-page 314 ? 2012 microchip technology inc. figure 17-5: alarm mask settings when alrmcfg = 00 and the chime bit = 0 (alrmcfg<6>), the repeat function is disabled and only a single alarm will occur. the alarm can be repeated up to 255 times by loading the alrmrpt register with ffh. after each alarm is issued, the alrmrpt register is decremented by one. once the register has reached ? 00 ?, the alarm will be issued one last time. after the alarm is issued a last time, the alrmen bit is cleared automatically and the alarm turned off. indefinite repetition of the alarm can occur if the chime bit = 1 . when chime = 1 , the alarm is not disabled when the alrmrpt register reaches ? 00 ?, but it rolls over to ff and continues counting indefinitely. 17.3.2 alarm interrupt at every alarm event, an interrupt is generated. addi- tionally, an alarm pulse output is provided that operates at half the frequency of the alarm. the alarm pulse output is completely synchronous with the rtcc clock and can be used as a trigger clock to other peripherals. this output is available on the rtcc pin. the output pulse is a clock with a 50% duty cycle and a frequency half that of the alarm event (see figure 17-6 ). the rtcc pin can also output the seconds clock. the user can select between the alarm pulse, generated by the rtcc module, or the seconds clock output. the rtsecsel<1:0> bits (rtccon2<1:0>) select between these two outputs: ? alarm pulse ? rtsecsel<1:0> = 00 ? seconds clock ? rtsecsel<1:0> = 01 note 1: annually, except when configured for february 29. s ss mss mm s s hh mm ss dhhmmss dd hh mm ss mm d d h h mm s s day of the week month day hours minutes seconds alarm mask setting amask<3:0> 0000 ? every half second 0001 ? every second 0010 ? every 10 seconds 0011 ? every minute 0100 ? every 10 minutes 0101 ? every hour 0110 ? every day 0111 ? every week 1000 ? every month 1001 ? every year (1)
? 2012 microchip technology inc. ds30575a-page 315 pic18f97j94 family figure 17-6: timer pulse generation 17.4 sleep mode the timer and alarm continue to operate while in sleep mode. the operation of the alarm is not affected by sleep, as an alarm event can always wake-up the cpu. the idle mode does not affect the operation of the timer or alarm. 17.5 reset 17.5.1 device reset when a device reset occurs, the alrmrpt register is forced to its reset state, causing the alarm to be disabled (if enabled prior to the reset). if the rtcc was enabled, it will continue to operate when a basic device reset occurs. 17.5.2 power-on reset (por) the rtccon1 and alrmrpt registers are reset only on a por. once the device exits the por state, the clock registers should be reloaded with the desired values. the timer prescaler values can be reset only by writing to the seconds register. no device reset can affect the prescalers. rtcen bit alrmen bit rtcc alarm event rtcc pin
pic18f97j94 family ds30575a-page 316 ? 2012 microchip technology inc. 17.6 register maps table 17-5 , tab l e 1 7- 6 and table 17-7 summarize the registers associated with the rtcc module. table 17-5: rtcc control registers file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 rtccon1 rtcen ? rtcwren rtcsync halfsec rtcoe rtcptr1 rtcptr0 rtccal cal7 cal6 cal5 cal4 cal3 cal2 cal1 cal0 rtccon2 pwcen pwcpol pwccpre pwcspre rtcclksel1 rtcclksel0 rtcsecsel1 rtcsecsel alrmcfg alrmen chime amask3 amask2 amask1 amask0 alrmptr1 alrmptr0 alrmrpt arpt7 arpt6 arpt5 arpt4 arpt3 arpt2 arpt1 arpt0 pmd3 txmmd ctmumd adcmd rtccmd lcdmd pspmd refo1md refo2md legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal for 80-pin devices. table 17-6: rtcc value registers file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 rtcvalh rtcc value high register window based on rtcptr<1:0> rtcvall rtcc value low register window based on rtcptr<1:0> table 17-7: alarm value registers file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 alrmvalh alarm value high register window based on alrmptr<1:0> alrmvall alarm value low register window based on alrmptr<1:0>
? 2012 microchip technology inc. ds30575a-page 317 pic18f97j94 family 18.0 enhanced capture/compare/pwm (eccp) module pic18f97j94 family devices have three enhanced capture/compare/pwm (eccp) modules: eccp1, eccp2 and eccp3. these modules contain a 16-bit register, which can operate as a 16-bit capture register, a 16-bit compare register or a pwm master/slave duty cycle register. these eccp modules are upward compatible with ccp eccp1, eccp2 and eccp3 are implemented as stan- dard ccp modules with enhanced pwm capabilities. these include: ? provision for two or four output channels ? output steering modes ? programmable polarity ? programmable dead-band control ? automatic shutdown and restart the enhanced features are discussed in detail in section 18.4 ?pwm (enhanced mode)? . the eccp1, eccp2 and eccp3 modules use the eccp control registers, ccp1con, ccp2con and ccp3con. the control registers, ccp4con through ccp10con, are for the modules, ccp4 through ccp10. note: throughout this section, generic references are used for register and bit names that are the same, except for an ?x? variable that indi- cates the item?s association with the ccp1, ccp2 or ccp3 module. for example, the control register is named ccpxcon and refers to ccp1con, ccp2con and ccp3con.
pic18f97j94 family ds30575a-page 318 ? 2012 microchip technology inc. register 18-1: ccpxcon: enhanced capture/compare/pwm x control r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pxm1 pxm0 dcxb1 dcxb0 ccpxm3 ccpxm2 ccpxm1 ccpxm0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 pxm<1:0>: enhanced pwm output configuration bits if ccpxm<3:2> = 00 , 01 , 10 : xx = pxa is assigned as the capture/compare input/output; pxb, pxc and pxd are assigned as port pins if ccpxm<3:2> = 11 : 00 = single output: pxa, pxb, pxc and pxd are controlled by steering (see section 18.4.7 ?pulse steering mode? ) 01 = full-bridge output forward: pxd is modulated; pxa is active; pxb, pxc are inactive 10 = half-bridge output: pxa, pxb are modulated with dead-band control; pxc and pxd are assigned as port pins 11 = full-bridge output reverse: pxb is modulated; pxc is active; pxa and pxd are inactive bit 5-4 dcxb<1:0>: pwm duty cycle bit capture mode: unused. compare mode: unused. pwm mode: these bits are the two lsbs of the 10-bit pwm duty cycle. the eight msbs of the duty cycle are found in ccprxl. bit 3-0 ccpxm<3:0> : ccpx mode select bits 0000 = capture/compare/pwm off (resets eccpx module) 0001 = reserved 0010 = compare mode: toggle output on match 0011 = reserved 0100 = capture mode: every falling edge 0101 = capture mode: every rising edge 0110 = capture mode: every fourth rising edge 0111 = capture mode: every 16 th rising edge 1000 = compare mode: initialize eccpx pin low, set output on compare match (set ccpxif) 1001 = compare mode: initialize eccpx pin high, clear output on compare match (set ccpxif) 1010 = compare mode: generate software interrupt only, eccpx pin reverts to i/o state 1011 = compare mode: trigger special event (eccpx resets tmr1 or tmr3, starts a/d conversion, sets ccpxif bit) 1100 = pwm mode: pxa and pxc are active-high; pxb and pxd are active-high 1101 = pwm mode: pxa and pxc are active-high; pxb and pxd are active-low 1110 = pwm mode: pxa and pxc are active-low; pxb and pxd are active-high 1111 = pwm mode: pxa and pxc are active-low; pxb and pxd are active-low
? 2012 microchip technology inc. ds30575a-page 319 pic18f97j94 family register 18-2: ccptmrs0: ccp timer select 0 register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 c3tsel1 c3tsel0 c2tsel2 c2tsel1 c2tsel0 c1tsel2 c1tsel1 c1tsel0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 c3tsel<1:0>: ccp3 timer selection bits 00 = ccp3 is based off of tmr1/tmr2 01 = ccp3 is based off of tmr3/tmr4 10 = ccp3 is based off of tmr3/tmr6 11 = ccp3 is based off of tmr3/tmr8 bit 5-3 c2tsel<2:0>: ccp2 timer selection bits 000 = ccp2 is based off of tmr1/tmr2 001 = ccp2 is based off of tmr3/tmr4 010 = ccp2 is based off of tmr3/tmr6 011 = ccp2 is based off of tmr3/tmr8 100 = reserved; do not use 101 = reserved; do not use 110 = reserved; do not use 111 = reserved; do not use bit 2-0 c1tsel<2:0>: ccp1 timer selection bits 000 = ccp1 is based off of tmr1/tmr2 001 = ccp1 is based off of tmr3/tmr4 010 = ccp1 is based off of tmr3/tmr6 011 = ccp1 is based off of tmr3/tmr8 100 = reserved; do not use 101 = reserved; do not use 110 = reserved; do not use 111 = reserved; do not use
pic18f97j94 family ds30575a-page 320 ? 2012 microchip technology inc. in addition to the expanded range of modes available through the ccpxcon, the eccp modules have three additional registers associated with enhanced pwm operation, pulse steering control and auto-shutdown features. they are: ? eccpxdel ? enhanced pwm x control ? pstrxcon ? pulse steering x control ? eccpxas ? auto-shutdown x control 18.1 eccp outputs and configuration the enhanced ccp module may have up to four pwm outputs, depending on the selected operating mode. these outputs, designated as pxa through pxd, are routed through the pps-lite module. therefore, individ- ual functions can be mapped to any of the remappable i/o pins (rpn). the outputs that are active depend on the eccp operating mode selected. the pin assignments are summarized in table 18-3 . to configure the i/o pins as pwm outputs, the proper pwm mode must be selected by setting the pxm<1:0> and ccpxm<3:0> bits. the appropriate tris direction bits for the port pins must also be set as outputs table 18-3 . 18.1.1 eccp module and timer resources the eccp modules use timers, 1, 2, 3, 4, 6 or 8, depending on the mode selected. these timers are available to ccp modules in capture, compare or pwm modes, as shown in table 18-1 . table 18-1: eccp mode ? timer resource the assignment of a particular timer to a module is determined by the timer to eccp enable bits in the ccptmrs0 register ( register 18-2 ). the interactions between the two modules are depicted in figure 18-1 . capture operations are designed to be used when the timer is configured for synchronous counter mode. capture operations may not work as expected if the associated timer is configured for asynchronous counter mode. eccp mode timer resource capture timer1 or timer3 compare timer1 or timer3 pwm timer2, timer4, timer6 or timer8
? 2012 microchip technology inc. ds30575a-page 321 pic18f97j94 family 18.2 capture mode in capture mode, the ccprxh:ccprxl register pair captures the 16-bit value of the tmr1 or tmr3 registers when an event occurs on the corresponding eccpx pin. an event is defined as one of the following: ? every falling edge ? every rising edge ? every fourth rising edge ?every 16 th rising edge the event is selected by the mode select bits, ccpxm<3:0> (ccpxcon<3:0>). when a capture is made, the interrupt request flag bit, ccpxif, is set (see table 18-2 ). the flag must be cleared by software. if another capture occurs before the value in the ccprxh/l register is read, the old captured value is overwritten by the new captured value. 18.2.1 eccp pin configuration in capture mode, the appropriate eccpx pin should be configured as an input by setting the corresponding tris direction bit. 18.2.2 timer1/2/3/4/5/6/8 mode selection the timers that are to be used with the capture feature (timer1/2/3/4/5/6 or 8) must be running in timer mode or synchronized counter mode. in asynchronous counter mode, the capture operation will not work. the timer to be used with each eccp module is selected in the ccptmrs0 register ( register 18-2 ). 18.2.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep the ccpxie interrupt enable bit clear to avoid false interrupts. the interrupt flag bit, ccpxif, should also be cleared following any such change in operating mode. 18.2.4 eccp prescaler there are four prescaler settings in capture mode; they are specified as part of the operating mode selected by the mode select bits (ccpxm<3:0>). whenever the eccp module is turned off, or capture mode is dis- abled, the prescaler counter is cleared. this means that any reset will clear the prescaler counter. switching from one capture prescaler to another may generate an interrupt. also, the prescaler counter will not be cleared; therefore, the first capture may be from a non-zero prescaler. example 18-1 provides the recommended method for switching between capture prescalers. this example also clears the prescaler counter and will not generate the ?false? interrupt. example 18-1: changing between capture prescalers figure 18-1: capture mode operation block diagram table 18-2: eccp1/2/3 interrupt flag bits eccp module flag bit 1 pir3<1> 2 pir3<2> 3 pir4<0> note: if the eccpx pin is configured as an out- put, a write to the port can cause a capture condition. clrf ccp1con ; turn eccp module off movlw new_capt_ps ; load wreg with the ; new prescaler mode ; value and eccp on movwf ccp1con ; load ccp1con with ; this value ccpr1h ccpr1l tmr1h tmr1l set ccp1if tmr3 enable q1:q4 ccp1con<3:0> eccp1 pin tmr1 enable c1tsel0 4 4 c1tsel1 c1tsel2 c1tsel0 c1tsel1 c1tsel2 and edge detect prescaler ? 1, 4, 16 tmr3h tmr3l
pic18f97j94 family ds30575a-page 322 ? 2012 microchip technology inc. 18.3 compare mode in compare mode, the 16-bit ccprx register value is constantly compared against the timer register pair value selected in the ccptmr0 register. when a match occurs, the eccpx pin can be: ? driven high ?driven low ? toggled (high-to-low or low-to-high) ? unchanged (that is, reflecting the state of the i/o latch) the action on the pin is based on the value of the mode select bits (ccpxm<3:0>). at the same time, the interrupt flag bit, ccpxif, is set. 18.3.1 eccpx pin configuration users must configure the eccpx pin as an output by clearing the appropriate tris bit. 18.3.2 timer1/2/3/4/5/6/8 mode selection timer1/2/3/4, 6 or 8, must be running in timer mode or synchronized counter mode if the eccp module is using the compare feature. in asynchronous counter mode, the compare operation will not work reliably. 18.3.3 software interrupt mode when the generate software interrupt mode is chosen (ccpxm<3:0> = 1010 ), the eccpx pin is not affected; only the ccpxif interrupt flag is affected. 18.3.4 special event trigger the eccp module is equipped with a special event trigger. this is an internal hardware signal generated in compare mode to trigger actions by other modules. the special event trigger is enabled by selecting the compare special event trigger mode (ccpxm<3:0> = 1011 ). the special event trigger resets the timer register pair for whichever timer resource is currently assigned as the module?s time base. this allows the ccprx registers to serve as a programmable period register for either timer. the special event trigger can also start an a/d conver- sion. in order to do this, the a/d converter must already be enabled. figure 18-2: compare mode operation block diagram note: clearing the ccpxcon register will force the eccpx compare output latch (depend- ing on device configuration) to the default low level. this is not the portx i/o data latch. tmr1h tmr1l tmr3h tmr3l ccpr1h ccpr1l set ccp1if 1 0 q s r output logic eccp1 pin tris ccp1con<3:0> output enable 4 (timer1/timer3 reset, a/d trigger) compare match c1tsel0 c1tsel1 c1tsel2 special event trigger comparator
? 2012 microchip technology inc. ds30575a-page 323 pic18f97j94 family 18.4 pwm (enhanced mode) the enhanced pwm mode can generate a pwm signal on up to four different output pins, with up to 10 bits of resolution. it can do this through four different pwm output modes: ? single pwm ? half-bridge pwm ? full-bridge pwm, forward mode ? full-bridge pwm, reverse mode to select an enhanced pwm mode, the pxm bits of the ccpxcon register must be set appropriately. the pwm outputs are multiplexed with i/o pins and are designated: pxa, pxb, pxc and pxd. the polarity of the pwm pins is configurable and is selected by setting the ccpxm bits in the ccpxcon register appropriately. table 18-1 provides the pin assignments for each enhanced pwm mode. figure 18-3 provides an example of a simplified block diagram of the enhanced pwm module. figure 18-3: example simplified block diagram of the enhanced pwm mode note: to prevent the generation of an incomplete waveform when the pwm is first enabled, the eccp module waits until the start of a new pwm period before generating a pwm signal. ccprxl ccprxh (slave) comparator tmr2 comparator pr2 (1) rq s duty cycle registers dcxb<1:0> clear timer2, toggle pwm pin and latch duty cycle note 1: the 8-bit tmr2 register is concatenated with the 2-bit inter nal q clock, or 2 bits of the prescaler, to create the 10-bit time base. 2: the tris register value for each pwm output must be configured appropriately. 3: any pin not used by an enhanced pwm mode is available for alternate pin functions. tris (2) eccp1/output pi n (3) tris (2) output pi n (3) tris (2) output pi n (3) tris (2) output pi n (3) output controller pxm<1:0> 2 ccpxm<3:0> 4 eccpxdel eccpx/pxa pxb pxc pxd
pic18f97j94 family ds30575a-page 324 ? 2012 microchip technology inc. table 18-3: example pin assignments for various pwm enhanced modes figure 18-4: example pwm (enhanced mode) output relationships (active-high state) eccp mode pxm<1:0> pxa pxb pxc pxd single 00 yes ( 1 ) yes ( 1 ) yes ( 1 ) yes ( 1 ) half-bridge 10 yes yes no no full-bridge, forward 01 yes yes yes yes full-bridge, reverse 11 yes yes yes yes note 1: outputs are enabled by pulse steering in single mode (see register 18-5 ). 0 period 00 10 01 11 signal pr2 + 1 pxm<1:0> pxa modulated pxa modulated pxb modulated pxa active pxb inactive pxc inactive pxd modulated pxa inactive pxb modulated pxc active pxd inactive pulse width (single output) (half-bridge) (full-bridge, forward) (full-bridge, reverse) delay (1) delay (1) relationships: ? period = 4 * t osc * (pr2 + 1) * (tmr2 prescale value) ? pulse width = t osc * (ccprxl<7:0>:ccpxcon<5:4>) * (tmr2 prescale value) ? delay = 4 * t osc * (eccpxdel<6:0>) note 1: dead-band delay is programmed using the eccpxdel register ( section 18.4.6 ?programmable dead-band delay mode? ).
? 2012 microchip technology inc. ds30575a-page 325 pic18f97j94 family figure 18-5: example enhanced pwm outp ut relationships (active-low state) 0 period 00 10 01 11 signal pr2 + 1 pxm<1:0> pxa modulated pxa modulated pxb modulated pxa active pxb inactive pxc inactive pxd modulated pxa inactive pxb modulated pxc active pxd inactive pulse width (single output) (half-bridge) (full-bridge, forward) (full-bridge, reverse) delay (1) delay (1) relationships: ? period = 4 * t osc * (pr2 + 1) * (tmr2 prescale value) ? pulse width = t osc * (ccprxl<7:0>:ccpxcon<5:4>) * (tmr2 prescale value) ? delay = 4 * t osc * (eccpxdel<6:0>) note 1: dead-band delay is programmed using the eccpxdel register ( section 18.4.6 ?programmable dead-band delay mode? ).
pic18f97j94 family ds30575a-page 326 ? 2012 microchip technology inc. 18.4.1 half-bridge mode in half-bridge mode, two pins are used as outputs to drive push-pull loads. the pwm output signal is output on the pxa pin, while the complementary pwm output signal is output on the pxb pin (see figure 18-6 ). this mode can be used for half-bridge applications, as shown in figure 18-7 , or for full-bridge applications, where four power switches are being modulated with two pwm signals. in half-bridge mode, the programmable dead-band delay can be used to prevent shoot-through current in half-bridge power devices. the value of the pxdc<6:0> bits of the eccpxdel register sets the number of instruction cycles before the output is driven active. if the value is greater than the duty cycle, the corresponding output remains inactive during the entire cycle. for more details on the dead-band delay operations, see section 18.4.6 ?programmable dead-band delay mode? . since the pxa and pxb outputs are multiplexed with the port data latches, the associated tris bits must be cleared to configure pxa and pxb as outputs. figure 18-6: example of half-bridge pwm output figure 18-7: example of half-bridge applications period pulse width td td (1) pxa (2) pxb (2) td = dead-band delay period (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: output signals are shown as active-high. pxa pxb fet driver fet driver load + - + - fet driver fet driver v+ load fet driver fet driver pxa pxb standard half-bridge circuit (?push-pull?) half-bridge output driving a full-bridge circuit
? 2012 microchip technology inc. ds30575a-page 327 pic18f97j94 family 18.4.2 full-bridge mode in full-bridge mode, all four pins are used as outputs. an example of a full-bridge application is provided in figure 18-8 . in the forward mode, the pxa pin is driven to its active state and the pxd pin is modulated, while the pxb and pxc pins are driven to their inactive state, as provided in figure 18-9 . in the reverse mode, the pxc pin is driven to its active state and the pxb pin is modulated, while the pxa and pxd pins are driven to their inactive state, as provided in figure 18-9 . the pxa, pxb, pxc and pxd outputs are multiplexed with the port data latches. the associated tris bits must be cleared to configure the pxa, pxb, pxc and pxd pins as outputs. figure 18-8: example of full-bridge application pxa pxc fet driver fet driver v+ v- load fet driver fet driver pxb pxd qa qb qd qc
pic18f97j94 family ds30575a-page 328 ? 2012 microchip technology inc. figure 18-9: example of full-bridge pwm output period pulse width pxa (2) pxb (2) pxc (2) pxd (2) forward mode (1) period pulse width pxa (2) pxc (2) pxd (2) pxb (2) reverse mode (1) (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: the output signal is shown as active-high.
? 2012 microchip technology inc. ds30575a-page 329 pic18f97j94 family 18.4.2.1 direction change in full-bridge mode in full-bridge mode, the pxm1 bit in the ccpxcon register allows users to control the forward/reverse direction. when the application firmware changes this direction control bit, the module will change to the new direction on the next pwm cycle. a direction change is initiated in software by changing the pxm1 bit of the ccpxcon register. the following sequence occurs prior to the end of the current pwm period: ? the modulated outputs (pxb and pxd) are placed in their inactive state. ? the associated unmodulated outputs (pxa and pxc) are switched to drive in the opposite direction. ? pwm modulation resumes at the beginning of the next period. for an illustration of this sequence, see figure 18-10 . the full-bridge mode does not provide a dead-band delay. as one output is modulated at a time, a dead-band delay is generally not required. there is a situation where a dead-band delay is required. this situation occurs when both of the following conditions are true: ? the direction of the pwm output changes when the duty cycle of the output is at or near 100%. ? the turn-off time of the power switch, including the power device and driver circuit, is greater than the turn-on time. figure 18-11 shows an example of the pwm direction changing from forward to reverse, at a near 100% duty cycle. in this example, at time, t1, the pxa and pxd outputs become inactive, while the pxc output becomes active. since the turn-off time of the power devices is longer than the turn-on time, a shoot-through current will flow through power devices, qc and qd (see figure 18-8 ), for the duration of ?t?. the same phenomenon will occur to power devices, qa and qb, for pwm direction change from reverse to forward. if changing pwm direction at high duty cycle is required for an application, two possible solutions for eliminating the shoot-through current are: ? reduce pwm duty cycle for one pwm period before changing directions. ? use switch drivers that can drive the switches off faster than they can drive them on. other options to prevent shoot-through current may exist. figure 18-10: example of pwm direction change pulse width period (1) signal note 1: the direction bit, pxm1 of the ccpxcon register, is written any time during the pwm cycle. 2: when changing directions, the pxa and pxc signals switch before the end of the current pwm cycle. the modulated pxb and pxd signals are inactive at this time. the length of this time is: (1/f osc ) ? tmr2 prescale value . period (2) pxa (active-high) pxb (active-high) pxc (active-high) pxd (active-high) pulse width
pic18f97j94 family ds30575a-page 330 ? 2012 microchip technology inc. figure 18-11: example of pwm direct ion change at near 100% duty cycle 18.4.3 start-up considerations when any pwm mode is used, the application hardware must use the proper external pull-up and/or pull-down resistors on the pwm output pins. the ccpxm<1:0> bits of the ccpxcon register allow the user to choose whether the pwm output signals are active-high or active-low for each pair of pwm output pins (pxa/pxc and pxb/pxd). the pwm output polarities must be selected before the pwm pin output drivers are enabled. changing the polarity configura- tion while the pwm pin output drivers are enabled is not recommended since it may result in damage to the application circuits. the pxa, pxb, pxc and pxd output latches may not be in the proper states when the pwm module is initialized. enabling the pwm pin output drivers, at the same time as the enhanced pwm modes, may cause damage to the application circuit. the enhanced pwm modes must be enabled in the proper output mode and complete a full pwm cycle before enabling the pwm pin output drivers. the completion of a full pwm cycle is indicated by the tmr2if or tmr4if bit of the pir1 or pir5 register being set as the second pwm period begins. 18.4.4 enhanced pwm auto-shutdown mode the pwm mode supports an auto-shutdown mode that will disable the pwm outputs when an external shutdown event occurs. auto-shutdown mode places the pwm output pins into a predetermined state. this mode is used to help prevent the pwm from damaging the application. the auto-shutdown sources are selected using the eccpxas<2:0> bits (eccpxas<6:4>). a shutdown event may be generated by: ? a logic ? 0 ? on the pin that is assigned the flt0 input function ? comparator c1 ? comparator c2 ? setting the eccpxase bit in firmware a shutdown condition is indicated by the eccpxase (auto-shutdown event status) bit (eccpxas<7>). if the bit is a ? 0 ?, the pwm pins are operating normally. if the bit is a ? 1 ?, the pwm outputs are in the shutdown state. forward period reverse period pxa t on t off t = t off ? t on pxb pxc pxd external switch d potential shoot-through current note 1: all signals are shown as active-high. 2: t on is the turn-on delay of pow er switch qc and its driver. 3: t off is the turn-off delay of power switch qd and its driver. external switch c t1 pw pw note: when the microcontroller is released from reset, all of the i/o pins are in the high-impedance state. the external circuits must keep the power switch devices in the off state until the microcontroller drives the i/o pins with the proper signal levels or activates the pwm output(s).
? 2012 microchip technology inc. ds30575a-page 331 pic18f97j94 family when a shutdown event occurs, two things happen: ? the eccpxase bit is set to ? 1 ?. the eccpxase will remain set until cleared in firmware or an auto-restart occurs. (see section 18.4.5 ?auto-restart mode? .) ? the enabled pwm pins are asynchronously placed in their shutdown states. the pwm output pins are grouped into pairs (pxa/pxc and pxb/pxd). the state of each pin pair is determined by the pssxac and pssxbd bits (eccpxas<3:2> and <1:0>, respectively). each pin pair may be placed into one of three states: ? drive logic ? 1 ? ? drive logic ? 0 ? ? tri-state (high-impedance) register 18-3: eccpxas: eccpx auto-shutdown control register ( 1 , 2 , 3 ) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eccpxase eccpxas2 eccpxas1 eccpxas0 pssxac1 pssxac0 pssxbd1 pssxbd0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 eccpxase: eccp auto-shutdown event status bit 1 = a shutdown event has occurred; eccp outputs are in a shutdown state 0 = eccp outputs are operating bit 6-4 eccpxas<2:0>: eccp auto-shutdown source select bits 000 = auto-shutdown is disabled 001 = comparator c1out output is high 010 = comparator c2out output is high 011 = either comparator c1out or c2out is high 100 =v il on flt0 pin 101 =v il on flt0 pin or comparator c1out output is high 110 =v il on flt0 pin or comparator c2out output is high 111 =v il on flt0 pin or comparator c1out or comparator c2out is high bit 3-2 pssxac<1:0>: pxa and pxc pins shutdown state control bits 00 = drive pins: pxa and pxc to ? 0 ? 01 = drive pins: pxa and pxc to ? 1 ? 1x = pxa and pxc pins tri-state bit 1-0 pssxbd<1:0>: pins pxb and pxd shutdown state control bits 00 = drive pins: pxb and pxd to ? 0 ? 01 = drive pins: pxb and pxd to ? 1 ? 1x = pxb and pxd pins tri-state note 1: the auto-shutdown condition is a level-based signal, not an edge-based signal. as long as the level is present, the auto-shutdown will persist. 2: writing to the eccpxase bit is disabled while an auto-shutdown condition persists. 3: once the auto-shutdown condition has been removed and the pwm restarted (either through firmware or auto-restart), the pwm signal will always restart at the beginning of the next pwm period.
pic18f97j94 family ds30575a-page 332 ? 2012 microchip technology inc. figure 18-12: pwm auto-shutdown wi th firmware restart (pxrsen = 0 ) 18.4.5 auto-restart mode the enhanced pwm can be configured to automatically restart the pwm signal once the auto-shutdown condi- tion has been removed. auto-restart is enabled by setting the pxrsen bit (eccpxdel<7>). if auto-restart is enabled, the eccpxase bit will remain set as long as the auto-shutdown condition is active. when the auto-shutdown condition is removed, the eccpxase bit will be cleared via hardware and normal operation will resume. the module will wait until the next pwm period begins, however, before re-enabling the output pin. this behav- ior allows the auto-shutdown with auto-restart features to be used in applications based on current mode of pwm control. figure 18-13: pwm auto-shutdown wi th auto-restart enabled (pxrsen = 1 ) shutdown pwm eccpxase bit activity event shutdown event occurs shutdown event clears pwm resumes normal pwm start of pwm period eccpxase cleared by firmware pwm period cleared by shutdown pwm eccpxase bit activity event shutdown event occurs shutdown event clears pwm resumes normal pwm start of pwm period pwm period
? 2012 microchip technology inc. ds30575a-page 333 pic18f97j94 family 18.4.6 programmable dead-band delay mode in half-bridge applications, where all power switches are modulated at the pwm frequency, the power switches normally require more time to turn off than to turn on. if both the upper and lower power switches are switched at the same time (one turned on and the other turned off), both switches may be on for a short period until one switch completely turns off. during this brief interval, a very high current (shoot-through current) will flow through both power switches, shorting the bridge supply. to avoid this potentially destructive shoot-through current from flowing during switching, turning on either of the power switches is normally delayed to allow the other switch to completely turn off. in half-bridge mode, a digitally programmable dead-band delay is available to avoid shoot-through current from destroying the bridge power switches. the delay occurs at the signal transition from the non-active state to the active state. for an illustration, see figure 18-14 . the lower seven bits of the associated eccpxdel register ( register 18-4 ) set the delay period in terms of microcontroller instruction cycles (t cy or 4 t osc ). figure 18-14: example of half-bridge pwm output figure 18-15: example of half-bridge applications period pulse width td td (1) pxa (2) pxb (2) td = dead-band delay period (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: output signals are shown as active-high. pxa pxb fet driver fet driver v+ v- load + v - + v - standard half-bridge circuit (?push-pull?)
pic18f97j94 family ds30575a-page 334 ? 2012 microchip technology inc. 18.4.7 pulse steering mode in single output mode, pulse steering allows any of the pwm pins to be the modulated signal. additionally, the same pwm signal can simultaneously be available on multiple pins. once the single output mode is selected (ccpxm<3:2> = 11 and pxm<1:0> = 00 of the ccpxcon register), the user firmware can bring out the same pwm signal to one, two, three or four output pins by setting the appropriate str bits (pstrxcon<3:0>), as provided in table 18-3 . while the pwm steering mode is active, the ccpxm<1:0> bits (ccpxcon<1:0>) select the pwm output polarity for the px pins. the pwm auto-shutdown operation also applies to the pwm steering mode, as described in section 18.4.4 ?enhanced pwm auto-shutdown mode? . an auto-shutdown event will only affect pins that have pwm outputs enabled. register 18-4: eccpxdel: enhanced pwm control register x r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pxrsen pxdc6 pxdc5 pxdc4 pxdc3 pxdc2 pxdc1 pxdc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pxrsen: pwm restart enable bit 1 = upon auto-shutdown, the eccpxase bit clears automatically once the shutdown event goes away; the pwm restarts automatically 0 = upon auto-shutdown, eccpxase must be cleared by software to restart the pwm bit 6-0 pxdc<6:0>: pwm delay count bits pxdcn = number of f osc /4 (4 * t osc ) cycles between the scheduled time when a pwm signal should transition active and the actual time it does transition active. note: the associated tris bits must be set to output (? 0 ?) to enable the pin output driver in order to see the pwm signal on the pin.
? 2012 microchip technology inc. ds30575a-page 335 pic18f97j94 family register 18-5: pstrxcon: pulse steering control ( 1 ) r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-1 cmpl1 cmpl0 ? strsync strd strc strb stra bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 cmpl<1:0>: complementary mode output assignment steering sync bits 00 = see str 01 = pa and pb are selected as the complementary output pair 10 = pa and pc are selected as the complementary output pair 11 = pa and pd are selected as the complementary output pair bit 5 unimplemented: read as ? 0 ? bit 4 strsync: steering sync bit 1 = output steering update occurs on the next pwm period 0 = output steering update occurs at the beginning of the instruction cycle boundary bit 3 strd: steering enable bit d 1 = pxd pin has the pwm waveform with polarity control from ccpxm<1:0> 0 = pxd pin is assigned to port pin bit 2 strc: steering enable bit c 1 = pxc pin has the pwm waveform with polarity control from ccpxm<1:0> 0 = pxc pin is assigned to port pin bit 1 strb: steering enable bit b 1 = pxb pin has the pwm waveform with polarity control from ccpxm<1:0> 0 = pxb pin is assigned to port pin bit 0 stra: steering enable bit a 1 = pxa pin has the pwm waveform with polarity control from ccpxm<1:0> 0 = pxa pin is assigned to port pin note 1: the pwm steering mode is available only when the ccpxcon register bits, ccpxm<3:2> = 11 and pxm<1:0> = 00 .
pic18f97j94 family ds30575a-page 336 ? 2012 microchip technology inc. figure 18-16: simplified steering block diagram 18.4.7.1 steering synchronization the strsync bit of the pstrxcon register gives the user two choices for when the steering event will happen. when the strsync bit is ? 0 ?, the steering event will happen at the end of the instruction that writes to the pstrxcon register. in this case, the out- put signal at the px pins may be an incomplete pwm waveform. this operation is useful when the user firmware needs to immediately remove a pwm signal from the pin. when the strsync bit is ? 1 ?, the effective steering update will happen at the beginning of the next pwm period. in this case, steering on/off the pwm output will always produce a complete pwm waveform. figures 18-17 and 18-18 illustrate the timing diagrams of the pwm steering depending on the strsync setting. figure 18-17: example of steering ev ent at end of instruction (strsync = 0) figure 18-18: example of steering event at beginning of instruction (strsync = 1) 1 0 tris output pin (1) port data pxa signal stra (2) 1 0 tris output pin (1) port data strb (2) 1 0 tris output pin (1) port data strc (2) 1 0 tris output pin (1) port data strd (2) note 1: port outputs are configured as displayed when the ccpxcon register bits, pxm<1:0> = 00 and ccpxm<3:2> = 11 . 2: single pwm output requires setting at least one of the strx bits. ccpxm1 ccpxm0 ccpxm1 ccpxm0 pwm p1n = pwm strn p1 port data pwm period port data pwm port data p1n = pwm strn p1 port data
? 2012 microchip technology inc. ds30575a-page 337 pic18f97j94 family 18.4.8 operation in power-managed modes in sleep mode, all clock sources are disabled. timer2/4/6/8 will not increment and the state of the module will not change. if the eccpx pin is driving a value, it will continue to drive that value. when the device wakes up, it will continue from this state. if two-speed start-ups are enabled, the initial start-up frequency from hf-intosc and the postscaler may not be stable immediately. in pri_idle mode, the primary clock will continue to clock the eccpx module without change. 18.4.8.1 operation with fail-safe clock monitor (fscm) if the fail-safe clock monitor (fscm) is enabled, a clock failure will force the device into the power-managed rc_run mode and the oscfif bit of the pir2 register will be set. the eccpx will then be clocked from the internal oscillator clock source, which may have a different clock frequency than the primary clock. 18.4.9 effects of a reset both power-on reset and subsequent resets will force all ports to input mode and the eccp registers to their reset states. this forces the eccp module to reset to a state compatible with previous, non-enhanced ccp modules used on other pic18 and pic16 devices.
pic18f97j94 family ds30575a-page 338 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 339 pic18f97j94 family 19.0 capture/compare/pwm (ccp) modules pic18f97j94 family devices have seven ccp (capture/compare/pwm) modules, designated ccp4 through ccp10. all the modules implement standard capture, compare and pulse-width modulation (pwm) modes. each ccp module contains a 16-bit register that can operate as a 16-bit capture register, a 16-bit compare register or a pwm master/slave duty cycle register. for the sake of clarity, all ccp module operation in the following sections is described with respect to ccp4, but is equally applicable to ccp5 through ccp10. note: throughout this section, generic references are used for register and bit names that are the same, except for an ?x? variable that indi- cates the item?s association with the specific ccp module. for example, the control register is named ccpxcon and refers to ccp4con through ccp10con. register 19-1: ccpxcon: ccpx contro l register (ccp4-ccp10 modules) u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? dcxb1 dcxb0 ccpxm3 ( 1 ) ccpxm2 ( 1 ) ccpxm1 ( 1 ) ccpxm0 ( 1 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 dcxb<1:0>: pwm duty cycle bit 1 and bit 0 for ccpx module bits capture mode: unused. compare mode: unused. pwm mode: these bits are the two least significant bits (bit 1 and bit 0) of the 10-bit pwm duty cycle. the eight most significant bits (dcx<9:2>) of the duty cycle are found in ccprxl. bit 3-0 ccpxm<3:0> : ccpx module mode select bits ( 1 ) 0000 = capture/compare/pwm is disabled (resets ccpx module) 0001 = reserved 0010 = compare mode, toggles output on match (ccpxif bit is set) 0011 = reserved 0100 = capture mode: every falling edge 0101 = capture mode: every rising edge 0110 = capture mode: every 4th rising edge 0111 = capture mode: every 16th rising edge 1000 = compare mode: initialize ccpx pin low; on compare match, force ccpx pin high (ccpxif bit is set) 1001 = compare mode: initialize ccpx pin high; on compare match, force ccpx pin low (ccpxif bit is set) 1010 = compare mode: generate software interrupt on compare match (ccpxif bit is set, ccpx pin reflects i/o state) 1011 = compare mode: special event trigger; reset timer on ccpx match (ccpxif bit is set) 11xx =pwm mode note 1: ccpxm<3:0> = 1011 will only reset the timer and not start an a/d conversion on a ccpx match.
pic18f97j94 family ds30575a-page 340 ? 2012 microchip technology inc. register 19-2: ccptmrs1: ccp timer select register 1 r/w-0 r/w-0 u-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 c7tsel1 c7tsel0 ? c6tsel0 ? c5tsel0 c4tsel1 c4tsel0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 c7tsel<1:0>: ccp7 timer selection bits 00 = ccp7 is based off of tmr1/tmr2 01 = ccp7 is based off of tmr5/tmr4 10 = ccp7 is based off of tmr5/tmr6 11 = ccp7 is based off of tmr5/tmr8 bit 5 unimplemented: read as ? 0 ? bit 4 c6tsel0: ccp6 timer selection bit 0 = ccp6 is based off of tmr1/tmr2 1 = ccp6 is based off of tmr5/tmr2 bit 3 unimplemented: read as ? 0 ? bit 2 c5tsel0: ccp5 timer selection bit 0 = ccp5 is based off of tmr1/tmr2 1 = ccp5 is based off of tmr5/tmr4 bit 1-0 c4tsel<1:0>: ccp4 timer selection bits 00 = ccp4 is based off of tmr1/tmr2 01 = ccp4 is based off of tmr3/tmr4 10 = ccp4 is based off of tmr3/tmr6 11 = reserved; do not use
? 2012 microchip technology inc. ds30575a-page 341 pic18f97j94 family register 19-3: ccptmrs2: ccp timer select register 2 u-0 u-0 u-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 ? ? ? c10tsel0 ? c9tsel0 c8tsel1 c8tsel0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 c10tsel0: ccp10 timer selection bit 0 = ccp10 is based off of tmr1/tmr2 1 = ccp10 is based off of tmr5/tmr2 bit 3 unimplemented: read as ? 0 ? bit 2 c9tsel0: ccp9 timer selection bit 0 = ccp9 is based off of tmr1/tmr2 1 = ccp9 is based off of tmr5/tmr4 bit 1-0 c8tsel<1:0>: ccp8 timer selection bits 00 = ccp8 is based off of tmr1/tmr2 01 = ccp8 is based off of tmr3/tmr4 10 = ccp8 is based off of tmr3/tmr6 11 = reserved; do not use
pic18f97j94 family ds30575a-page 342 ? 2012 microchip technology inc. register 19-4: ccprxl: ccpx period low byte register r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ccprxl7 ccprxl6 ccprxl5 ccprxl4 ccprxl3 ccprxl2 ccprxl1 ccprxl0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 ccprxl<7:0>: ccpx period register low byte bits capture mode: capture register low byte compare mode: compare register low byte pwm mode: duty cycle register register 19-5: ccprxh: ccpx period high byte register r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ccprxh7 ccprxh6 ccprxh5 ccprxh4 ccprxh3 ccprxh2 ccprxh1 ccprxh0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 ccprxh<7:0>: ccpx period register high byte bits capture mode: capture register high byte compare mode: compare register high byte pwm mode: duty cycle buffer register
? 2012 microchip technology inc. ds30575a-page 343 pic18f97j94 family 19.1 ccp module configuration each capture/compare/pwm module is associated with a control register (generically, ccpxcon) and a data register (ccprx). the data register, in turn, is comprised of two 8-bit registers: ccprxl (low byte) and ccprxh (high byte). all registers are both readable and writable. 19.1.1 ccp modules and timer resources the ccp modules utilize timers, 1 through 8, that vary with the selected mode. various timers are available to the ccp modules in capture, compare or pwm modes, as shown in table 19-1 . table 19-1: ccp mode ? timer resource the assignment of a particular timer to a module is determined by the timer to ccp enable bits in the ccptmrsx registers. (see register 19-2 and register 19-3 .) all of the modules may be active at once and may share the same timer resource if they are configured to operate in the same mode (capture/compare or pwm) at the same time. the ccptmrs1 register selects the timers for ccp modules, 7, 6, 5 and 4, and the ccptmrs2 register selects the timers for ccp modules, 10, 9 and 8. the possible configurations are shown in ta b l e 1 9 - 2 and table 19-3 . table 19-2: timer assignments for ccp modules 4, 5, 6 and 7 table 19-3: timer assignments for ccp modules 8, 9 and 10 ccp mode timer resource capture timer1, timer3 or timer 5 compare pwm timer2, timer4, timer 6 or timer8 ccptmrs1 register ccp4 ccp5 ccp6 ccp7 c4tsel <1:0> capture/ compare mode pwm mode c5tsel0 capture/ compare mode pwm mode c6tsel0 capture/ compare mode pwm mode c7tsel <1:0> capture/ compare mode pwm mode 00 tmr1 tmr2 0 tmr1 tmr2 0 tmr1 tmr2 00 tmr1 tmr2 01 tmr3 tmr4 1 tmr5 tmr4 1 tmr5 tmr2 01 tmr5 tmr4 10 tmr3 tmr6 10 tmr5 tmr6 11 reserved ( 1 ) 11 tmr5 tmr8 note 1: do not use the reserved bits. ccptmrs2 register ccp8 ccp8 devices with 32 kbytes ccp9 ccp10 c8tsel <1:0> capture/ compare mode pwm mode c8tsel <1:0> capture/ compare mode pwm mode c9tsel0 capture/ compare mode pwm mode c10tsel0 capture/ compare mode pwm mode 00 tmr1 tmr2 00 tmr1 tmr2 0 tmr1 tmr2 0 tmr1 tmr2 01 tmr5 tmr4 01 tmr1 tmr4 1 tmr5 tmr4 1 tmr5 tmr2 10 tmr5 tmr6 10 tmr1 tmr6 11 reserved ( 1 ) 11 reserved ( 1 ) note 1: do not use the reserved bits.
pic18f97j94 family ds30575a-page 344 ? 2012 microchip technology inc. 19.1.2 open-drain output option when operating in output mode (the compare or pwm modes), the drivers for the ccpx pins can be optionally configured as open-drain outputs. this feature allows the voltage level on the pin to be pulled to a higher level through an external pull-up resistor and allows the output to communicate with external circuits without the need for additional level shifters. the open-drain output option is controlled by the ccpxod bits (odcon2<7:1>). setting the appropri- ate bit configures the pin for the corresponding module for open-drain operation. 19.2 capture mode in capture mode, the ccpr4h:ccpr4l register pair captures the 16-bit value of the timer register selected in the ccptmrs1 when an event occurs on the ccp4 pin. an event is defined as one of the following: ? every falling edge ? every rising edge ? every 4th rising edge ? every 16th rising edge the event is selected by the mode select bits, ccp4m<3:0> (ccp4con<3:0>). when a capture is made, the interrupt request flag bit, ccp4if (pir4<1>), is set. (it must be cleared in software.) if another capture occurs before the value in ccpr4 is read, the old captured value is overwritten by the new captured value. figure 19-1 shows the capture mode block diagram. 19.2.1 ccp pin configuration in capture mode, the appropriate ccpx pin should be configured as an input by setting the corresponding tris direction bit. 19.2.2 timer1/3/5/7 mode selection for the available timers (1/3/5) to be used for the capture feature, the used timers must be running in timer mode or synchronized counter mode. in asynchronous counter mode, the capture operation will not work. the timer to be used with each ccp module is selected in the ccptmrsx registers. (see section 19.1.1 ?ccp modules and timer resources? .) details of the timer assignments for the ccp modules are given in table 19-2 and table 19-3 . note: if the ccpx pin is configured as an output, a write to the port can cause a capture condition.
? 2012 microchip technology inc. ds30575a-page 345 pic18f97j94 family figure 19-1: capture mode operation block diagram 19.2.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep the ccp4ie bit (pie4<1>) clear to avoid false interrupts and should clear the flag bit, ccp4if, following any such change in operating mode. 19.2.4 ccp prescaler there are four prescaler settings in capture mode. they are specified as part of the operating mode selected by the mode select bits (ccp4m<3:0>). whenever the ccp module is turned off, or the ccp module is not in capture mode, the prescaler counter is cleared. this means that any reset will clear the prescaler counter. switching from one capture prescaler to another may generate an interrupt. doing that will also not clear the prescaler counter ? meaning the first capture may be from a non-zero prescaler. example 19-1 shows the recommended method for switching between capture prescalers. this example also clears the prescaler counter and will not generate the ?false? interrupt. example 19-1: changing between capture prescalers ccpr5h ccpr5l tmr1h tmr1l set ccp5if tmr5 enable q1:q4 ccp5con<3:0> ccp5 pin prescaler ? 1, 4, 16 and edge detect tmr1 enable c5tsel0 c5tsel0 ccpr4h ccpr4l tmr1h tmr1l set ccp4if tmr3 enable ccp4con<3:0> ccp4 pin prescaler ? 1, 4, 16 tmr3h tmr3l tmr1 enable c4tsel0 c4tsel1 c4tsel0 c4tsel1 tmr5h tmr5l and edge detect 4 4 4 note: this block diagram uses ccp4 and ccp5, and their appropr iate timers as an example. for details on all of the ccp modules and their timer assignments, see table 19-2 and table 19-3 . clrf ccp4con ; turn ccp module off movlw new_capt_ps ; load wreg with the ; new prescaler mode ; value and ccp on movwf ccp4con ; load ccp4con with ; this value
pic18f97j94 family ds30575a-page 346 ? 2012 microchip technology inc. 19.3 compare mode in compare mode, the 16-bit ccpr4 register value is constantly compared against the timer register pair value selected in the ccptmr1 register. when a match occurs, the ccp4 pin can be: ? driven high ?driven low ? toggled (high-to-low or low-to-high) ? unchanged (that is, reflecting the state of the i/o latch) the action on the pin is based on the value of the mode select bits (ccp4m<3:0>). at the same time, the interrupt flag bit, ccp4if, is set. figure 19-2 gives the compare mode block diagram 19.3.1 ccp pin configuration the user must configure the ccpx pin as an output by clearing the appropriate tris bit. 19.3.2 timer1/3/5 mode selection if the ccp module is using the compare feature in conjunction with any of the timer1/3/5 timers, the timers must be running in timer mode or synchronized counter mode. in asynchronous counter mode, the compare operation will not work. 19.3.3 software interrupt mode when the generate software interrupt mode is chosen (ccp4m<3:0> = 1010 ), the ccp4 pin is not affected. only a ccp interrupt is generated, if enabled, and the ccp4ie bit is set. 19.3.4 special event trigger both ccp modules are equipped with a special event trigger. this is an internal hardware signal, generated in compare mode, to trigger actions by other modules. the special event trigger is enabled by selecting the compare special event trigger mode (ccp4m<3:0> = 1011 ). for either ccp module, the special event trigger resets the timer register pair for whichever timer resource is currently assigned as the module?s time base. this allows the ccprx registers to serve as a programmable period register for either timer. the special event trigger for ccp4 cannot start an a/d conversion. note: clearing the ccpxcon register will force the ccpx compare output latch (depend- ing on device configuration) to the default low level. this is not the portx i/o data latch. note: details of the timer assignments for the ccp modules are given in table 19-2 and ta b l e 1 9 - 3 .
? 2012 microchip technology inc. ds30575a-page 347 pic18f97j94 family figure 19-2: compare mode operat ion block diagram ccpr5h ccpr5l tmr1h tmr1l comparator q s r output logic special event trigger set ccp5if ccp5 pin tris ccp5con<3:0> output enable tmr5h tmr5l 1 0 compare 4 (timer1/5 reset) match note: this block diagram uses ccp4 and cc p5 and their appropriate timers as an example. for details on all of the ccp modules and their timer assignments, see table 19-2 and table 19-3 . tmr1h tmr1l tmr3h tmr3l ccpr4h ccpr4l comparator c4tsel1 set ccp4if 1 0 q s r output logic special event trigger ccp4 pin tris ccp4con<3:0> output enable 4 (timer1/timer3 reset) compare match c5tsel0 c4tsel0
pic18f97j94 family ds30575a-page 348 ? 2012 microchip technology inc. 19.4 pwm mode in pulse-width modulation (pwm) mode, the ccp4 pin produces up to a 10-bit resolution pwm output. since the ccp4 pin is multiplexed with a portc or porte data latch, the appropriate tris bit must be cleared to make the ccp4 pin an output. figure 19-3 shows a simplified block diagram of the ccp4 module in pwm mode. for a step-by-step procedure on how to set up the ccp module for pwm operation, see section 19.4.3 ?setup for pwm operation? . figure 19-3: simplified pwm block diagram a pwm output ( figure 19-4 ) has a time base (period) and a time that the output stays high (duty cycle). the frequency of the pwm is the inverse of the period (1/period). figure 19-4: pwm output 19.4.1 pwm period the pwm period is specified by writing to the pr2 register. the pwm period can be calculated using the following formula: equation 19-1: pwm period calculation pwm frequency is defined as 1/[pwm period]. when tmr2 is equal to pr2, the following three events occur on the next increment cycle: ?tmr2 is cleared ? the ccp4 pin is set (an exception: if pwm duty cycle = 0%, the ccp4 pin will not be set) ? the pwm duty cycle is latched from ccpr4l into ccpr4h note: clearing the ccpxcon register will force the ccpx compare output latch (depend- ing on device configuration) to the default low level. this is not the portx i/o data latch. ccpr4l ccpr4h (slave) comparator tmr2 comparator pr2 (note 1) r q s duty cycle registers ccp4con<5:4> clear timer, ccp4 pin and latch d.c. trisc<2> rc2/ccp4 note 1: the 8-bit tmr2 value is concatenated with the 2-bit internal q clock, or 2 bits of the prescaler, to create the 10-bit time base. 2: ccp4 and its appropriate timers are used as an example. for details on all of the ccp modules and their timer assignments, see table 19-2 and table 19-3 . note: the timer2 postscalers (see section 16.0 ?timer2/4/6/8 modules? ) are not used in the determination of the pwm frequency. the postscaler could be used to have a servo update rate at a dif- ferent frequency than the pwm output. period duty cycle tmr2 = pr2 tmr2 = duty cycle tmr2 = pr2 pwm period = [(pr2) + 1] ? 4 ? t osc ? (tmr2 prescale value)
? 2012 microchip technology inc. ds30575a-page 349 pic18f97j94 family 19.4.2 pwm duty cycle the pwm duty cycle is specified, to use ccp4 as an example, by writing to the ccpr4l register and to the ccp4con<5:4> bits. up to 10-bit resolution is avail- able. the ccpr4l contains the eight msbs and the ccp4con<5:4> contains the two lsbs. this 10-bit value is represented by ccpr4l:ccp4con<5:4>. the following equation is used to calculate the pwm duty cycle in time: equation 19-2: pwm duty cycle (in time) ccpr4l and ccp4con<5:4> can be written to at any time, but the duty cycle value is not latched into ccpr4h until after a match between pr2 and tmr2 occurs (that is, the period is complete). in pwm mode, ccpr4h is a read-only register. the ccpr4h register and a two-bit internal latch are used to double-buffer the pwm duty cycle. this double-buffering is essential for glitchless pwm operation. when the ccpr4h and two-bit latch match tmr2, concatenated with an internal two-bit q clock or two bits of the tmr2 prescaler, the ccp4 pin is cleared. the maximum pwm resolution (bits) for a given pwm frequency is given by the equation: equation 19-3: pwm resolution table 19-4: example pwm frequencies and resolutions at 40 mhz 19.4.3 setup for pwm operation to configure the ccp module for pwm operation using ccp4 as an example: 1. set the pwm period by writing to the pr2 register. 2. set the pwm duty cycle by writing to the ccpr4l register and ccp4con<5:4> bits. 3. make the ccp4 pin an output by clearing the appropriate tris bit. 4. set the tmr2 prescale value, then enable timer2 by writing to t2con. 5. configure the ccp4 module for pwm operation. pwm duty cycle = (ccpr4l:ccp4con<5:4>) ? t osc ? (tmr2 prescale value) note: if the pwm duty cycle value is longer than the pwm period, the ccp4 pin will not be cleared. f osc f pwm --------------- ?? ?? log 2 ?? log ----------------------------- b i t s = pwm resolution (max) pwm frequency 2.44 khz 9.77 khz 39.06 khz 156.25 khz 312.50 khz 416.67 khz timer prescaler (1, 4, 16)1641111 pr2 value ffh ffh ffh 3fh 1fh 17h maximum resolution (bits) 10 10 10 8 7 6.58
pic18f97j94 family ds30575a-page 350 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 351 pic18f97j94 family 20.0 master synchronous serial port (mssp) module 20.1 master ssp (mssp) module overview the master synchronous serial port (mssp) module is a serial interface, useful for communicating with other peripheral or microcontroller devices. these peripheral devices may be serial eeproms, shift registers, display drivers, a/d converters, etc. the mssp module can operate in one of two modes: ? serial peripheral interface (spi) ? inter-integrated circuit? (i 2 c?) - full master mode - slave mode (with general address call) the i 2 c interface supports the following modes in hardware: ?master mode ? multi-master mode ? slave mode with 5-bit and 7-bit address masking (with address masking for both 10-bit and 7-bit addressing) all members of the pic18f97j94 family have two mssp modules, designated as mssp1 and mssp2. each module operates independently of the other. 20.2 control registers each mssp module has four associated control regis- ters. these include a status register (sspxstat) and three control registers (sspxcon1, sspxcon2, and sspxcon3). the use of these registers and their indi- vidual configuration bits differ significantly depending on whether the mssp module is operated in spi or i 2 c mode. additional details are provided under the individual sections. on all pic18f97j94 family devices, the spi dma capability can only be used in conjunction with mssp1. the spi dma feature is described in section 20.4 ?spi dma module? . note: throughout this section, generic refer- ences to an mssp module in any of its operating modes may be interpreted as being equally applicable to mssp1 or mssp2. register names and module i/o signals use the generic designator ?x? to indicate the use of a numeral to distin- guish a particular module when required. control bit names are not individuated. note: in devices with more than one mssp module, it is very important to pay close attention to sspxcon register names. ssp1con1 and ssp1con2 control different operational aspects of the same module, while ssp1con1 and ssp2con1 control the same features for two different modules. note: the sspxbuf register cannot be used with read-modify-write instructions, such as bcf , comf , etc. to avoid lost data in master mode, a read of the sspxbuf must be per- formed to clear the buffer full (bf) detect bit (sspstat<0>) between each transmission.
pic18f97j94 family ds30575a-page 352 ? 2012 microchip technology inc. 20.3 spi mode the spi mode allows 8 bits of data to be synchronously transmitted and received simultaneously. all four modes of spi are supported. to accomplish communi- cation, three pins are typically used. these pins must be assigned through the pps-lite configuration registers before use. ? serial data out (sdox) ? mapped to pin using pps-lite peripheral output registers ? serial data in (sdix) ? mapped to pin using pps-lite peripheral input registers ? serial clock (sckx) ? mapped to pin using pps-lite peripheral input registers (for slave mode) or peripheral output registers (for master mode). additionally, a fourth pin may be used when in a slave mode of operation: ? slave select (ssx ) ? mapped through pps-lite peripheral input registers figure 20-1 shows the block diagram of the msspx module when operating in spi mode. figure 20-1: msspx block diagram (spi mode) ( ) read write internal data bus sspxsr reg sspm<3:0> bit 0 shift clock ssx control enable edge select clock select tmr2 output t osc prescaler 4, 16, 64 2 edge select 2 4 data to txx/rxx in sspxsr tris bit 2 smp:cke sdox sspxbuf reg sdix ssx sckx note: pps-lite signal names are used in this dia- gram for the sake of brevity. refer to the text for a full list of multiplexed functions.
? 2012 microchip technology inc. ds30575a-page 353 pic18f97j94 family 20.3.1 registers each mssp module has four registers for spi mode operation. these are: ? msspx control register 1 (sspxcon1) ? msspx status register (sspxstat) ? msspx control register 3 (sspxcon3) ? serial receive/transmit buffer register (sspxbuf) ? msspx shift register (sspxsr) ? not directly accessible sspxcon1, sspxcon3 and sspxstat are the con- trol and status registers in spi mode operation. the sspxcon1 and sspxcon3 registers are readable and writable. the lower 6 bits of the sspxstat are read-only. the upper two bits of the sspxstat are read/write. sspxsr is the shift register used for shifting data in or out. sspxbuf is the buffer register to which data bytes are written to or read from. in receive operations, sspxsr and sspxbuf together, create a double-buffered receiver. when sspxsr receives a complete byte, it is transferred to sspxbuf and the sspxif interrupt is set. during transmission, the sspxbuf is not double- buffered. a write to sspxbuf will write to both sspxbuf and sspxsr. register 20-1: sspxstat: msspx status register (spi mode ) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke ( 1 ) d/a psr/w ua bf bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 smp: sample bit spi master mode: 1 = input data is sampled at the end of data output time 0 = input data is sampled at the middle of data output time spi slave mode: smp must be cleared when spi is used in slave mode. bit 6 cke: spi clock select bit ( 1 ) 1 = transmit occurs on the transition from active to idle clock state 0 = transmit occurs on the transition from idle to active clock state bit 5 d/a : data/address bit used in i 2 c? mode only. bit 4 p: stop bit used in i 2 c mode only. this bit is cleared when the msspx module is disabled; sspen is cleared. bit 3 s: start bit used in i 2 c mode only. bit 2 r/w : read/write information bit used in i 2 c mode only. bit 1 ua: update address bit used in i 2 c mode only. bit 0 bf: buffer full status bit (receive mode only) 1 = receive is complete, sspxbuf is full 0 = receive is not complete, sspxbuf is empty note 1: polarity of clock state is set by the ckp bit (sspxcon1<4>).
pic18f97j94 family ds30575a-page 354 ? 2012 microchip technology inc. register 20-2: sspxcon1: msspx co ntrol register 1 (spi mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov ( 1 ) sspen ( 2 ) ckp sspm3 ( 4 ) sspm2 ( 4 ) sspm1 ( 4 ) sspm0 ( 4 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wcol: write collision detect bit 1 = the sspxbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision bit 6 sspov: receive overflow indicator bit ( 1 ) spi slave mode: 1 = a new byte is received while the sspxbuf register is still holding the previous data. in case of overflow, the data in sspxsr is lost. overflow can only occur in slave mode. the user must read the sspxbuf, even if only transmitting data, to avoid setting overflow (must be cleared in software). 0 = no overflow bit 5 sspen: master synchronous serial port enable bit ( 2 ) 1 = enables serial port and configures sckx, sdox, sdix and ssx as serial port pins 0 = disables serial port and configures these pins as i/o port pins bit 4 ckp: clock polarity select bit 1 = idle state for the clock is a high level 0 = idle state for the clock is a low level bit 3-0 sspm<3:0>: master synchronous serial port mode select bits ( 4 ) 1010 = spi master mode: clock = f osc /(4 * (sspxadd + 1) ( 3 ) 0101 = spi slave mode: clock = sckx pin; ssx pin control is disabled; ssx can be used as i/o pin 0100 = spi slave mode: clock = sckx pin; ssx pin control is enabled 0011 = spi master mode: clock = tmr2 output/2 0010 = spi master mode: clock = f osc /64 0001 = spi master mode: clock = f osc /16 0000 = spi master mode: clock = f osc /4 note 1: in master mode, the overflow bit is not set since each new reception (and transmission) is initiated by writing to the sspxbuf register. 2: when enabled, these pins must be properly configured as inputs or outputs. 3: sspxadd = 0 is not supported. 4: bit combinations not specifically listed here are either reserved or implemented in i 2 c? mode only.
? 2012 microchip technology inc. ds30575a-page 355 pic18f97j94 family register 20-3: sspxcon3: mssp co ntrol register 3 (spi mode) r/hs/hc-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 acktim pcie scie boen sdaht sbcde ahen dhen bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 acktim: acknowledge time status bit unused in spi. bit 6 pcie: stop condition interrupt enable bit ( 1 ) 1 = enable interrupt on detection of stop condition 0 = stop detection interrupts are disabled bit 5 scie: start condition interrupt enable bit ( 1 ) 1 = enable interrupt on detection of start or restart conditions 0 = start detection interrupts are disabled bit 4 boen: buffer overwrite enable bit ( 2 ) 1 = sspbuf updates every time a new data byte is shifted in, ignoring the bf bit 0 = if a new byte is received with bf bit already set, sspov is set, and the buffer is not updated bit 3 sdaht: sda hold time selection bit unused in spi. bit 2 sbcde: slave mode bus collision detect enable bit unused in spi. bit 1 ahen: address hold enable bit unused in spi. bit 0 dhen: data hold enable bit unused in spi. note 1: this bit has no effect in slave modes that start and stop condition detection is explicitly listed as enabled. 2: for daisy-chained spi operation; allows the user to ignore all but the last received byte. sspov is still set when a new byte is received and bf = 1 , but hardware continues to write the most recent byte to sspxbuf.
pic18f97j94 family ds30575a-page 356 ? 2012 microchip technology inc. 20.3.2 operation when initializing the spi, several options need to be specified. this is done by programming the appropriate control bits (sspxcon1<5:0> and sspxstat<7:6>). these control bits allow the following to be specified: ? i/o pins must be mapped to the spi peripheral in order to function. see section 11.15 ?pps-lite? for an explanation of the pps-lite mapping feature. ? master mode (sckx is the clock output) ? slave mode (sckx is the clock input) ? clock polarity (idle state of sckx) ? data input sample phase (middle or end of data output time) ? clock edge (output data on rising/falling edge of sckx) ? clock rate (master mode only) ? slave select mode (slave mode only) each msspx module consists of a transmit/receive shift register (sspxsr) and a buffer register (sspxbuf). the sspxsr shifts the data in and out of the device, msb first. the sspxbuf holds the data that was written to the sspxsr until the received data is ready. once the 8 bits of data have been received, that byte is moved to the sspxbuf register. then, the buffer full detect bit, bf (sspxstat<0>), and the interrupt flag bit, sspxif, are set. this double-buffering of the received data (sspxbuf) allows the next byte to start reception before reading the data that was just received. any write to the sspxbuf register during transmission/reception of data will be ignored and the write collision detect bit, wcol (sspxcon1<7>), will be set. user software must clear the wcol bit so that it can be determined if the following write(s) to the sspxbuf register completed successfully. when the application software is expecting to receive valid data, the sspxbuf should be read before the next byte of data to transfer is written to the sspxbuf. the buffer full bit, bf (sspxstat<0>), indicates when sspxbuf has been loaded with the received data (transmission is complete). when the sspxbuf is read, the bf bit is cleared. this data may be irrelevant if the spi is only a transmitter. generally, the msspx interrupt is used to determine when the transmission/ reception has completed. if the interrupt method is not going to be used, then software polling can be done to ensure that a write collision does not occur. example 20-1 shows the loading of the sspxbuf (sspxsr) for data transmission. the sspxsr is not directly readable or writable and can only be accessed by addressing the sspxbuf register. additionally, the sspxstat register indicates the various status conditions. 20.3.3 open-drain output option the drivers for the sdox output and sckx clock pins can be optionally configured as open-drain outputs. this feature allows the voltage level on the pin to be pulled to a higher level through an external pull-up resistor, and allows the output to communicate with external circuits without the need for additional level shifters. for more information, see section 11.1.3 ?open-drain outputs? . the open-drain output option is controlled by the sspxod bits (odcon1<1:0>). setting an sspxod bit configures the sdox and sckx pins for the corresponding module for open-drain operation. example 20-1: loading the ssp1buf (ssp1sr) register note: to avoid lost data in master mode, a read of the sspxbuf must be per- formed to clear the buffer full (bf) detect bit (sspxstat<0>) between each transmission. loop btfss ssp1stat, bf ;has data been received (transmit complete)? bra loop ;no movf ssp1buf, w ;wreg reg = contents of ssp1buf movwf rxdata ;save in user ram, if data is meaningful movf txdata, w ;w reg = contents of txdata movwf ssp1buf ;new data to xmit
? 2012 microchip technology inc. ds30575a-page 357 pic18f97j94 family 20.3.4 enabling spi i/o to enable the serial port, the peripheral must first be mapped to i/o pins using the pps-lite feature. to enable the spi peripheral, the msspx enable bit, sspen (sspxcon1<5>) must be set. to reset or reconfigure spi mode, clear the sspen bit, re-initialize the sspxcon registers and then set the sspen bit. this configures the sdix, sdox, sckx and ssx pins as serial port pins. for the pins to behave as the serial port function, some must have their data direction bits (in the tris register) appropriately programmed as follows: ? sdix is automatically controlled by the spi module ? sdox must have the tris bit cleared for the corresponding rpn pin. ? sckx (master mode) must have the tris bit cleared for the corresponding rpn pin ? sckx (slave mode) must have the tris bit set for the corresponding rpn pin ? ssx must have the tris bit set for the corresponding rpn pin. any serial port function that is not desired may be overridden by programming the corresponding data direction (tris) register to the opposite value. 20.3.5 typical connection figure 20-2 shows a typical connection between two microcontrollers. the master controller (processor 1) initiates the data transfer by sending the sckx signal. data is shifted out of both shift registers on their pro- grammed clock edge and latched on the opposite edge of the clock. both processors should be programmed to the same clock polarity (ckp), then both controllers would send and receive data at the same time. whether the data is meaningful (or dummy data) depends on the application software. this leads to three scenarios for data transmission: ? master sends data ? ? ? slave sends dummy data ? master sends data ? ? ? slave sends data ? master sends dummy data ? ? ? slave sends data figure 20-2: spi master/slave connection serial input buffer (sspxbuf) shift register (sspxsr) msb lsb sdox sdix processor 1 sckx spi master sspm<3:0> = 00xxb serial input buffer (sspxbuf) shift register (sspxsr) lsb msb sdix sdox processor 2 sckx spi slave sspm<3:0> = 010x b serial clock
pic18f97j94 family ds30575a-page 358 ? 2012 microchip technology inc. 20.3.6 master mode the master can initiate the data transfer at any time because it controls the sckx signal. the master deter- mines when the slave (processor 2, figure 20-2 ) is to broadcast data by the software protocol. in master mode, the data is transmitted/received as soon as the sspxbuf register is written to. if the spi is only going to receive, the sdox output could be dis- abled (programmed as an input). the sspxsr register will continue to shift in the signal present on the sdix pin at the programmed clock rate. as each byte is received, it will be loaded into the sspxbuf register as if a normal received byte (interrupts and status bits appropriately set). this could be useful in receiver applications as a ?line activity monitor? mode. the clock polarity is selected by appropriately program- ming the ckp bit (sspxcon1<4>). this, then, would give waveforms for spi communication, as shown in figure 20-3 , figure 20-5 and figure 20-6 , where the msb is transmitted first. in master mode, the spi clock rate (bit rate) is user-programmable to be one of the following: ?f osc /4 (or t cy ) ?f osc /(4 * (sspxadd + 1) ?f osc /16 (or 4 ? t cy ) ?f osc /64 (or 16 ? t cy ) ? timer2 output/2 this allows a maximum data rate (at 64 mhz) of 16.00 mbps. figure 20-3 shows the waveforms for master mode. when the cke bit is set, the sdox data is valid before there is a clock edge on sckx. the change of the input sample is shown based on the state of the smp bit. the time when the sspxbuf is loaded with the received data is shown. figure 20-3: spi mode waveform (master mode) sckx (ckp = 0 sckx (ckp = 1 sckx (ckp = 0 sckx (ckp = 1 4 clock modes input sample input sample sdix bit 7 bit 0 sdox bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 sdix sspxif (smp = 1 ) (smp = 0 ) (smp = 1 ) cke = 1 ) cke = 0 ) cke = 1 ) cke = 0 ) (smp = 0 ) write to sspxbuf sspxsr to sspxbuf sdox bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 (cke = 0 ) (cke = 1 ) next q4 cycle after q2 ? bit 0
? 2012 microchip technology inc. ds30575a-page 359 pic18f97j94 family 20.3.7 slave mode in slave mode, the data is transmitted and received as the external clock pulses appear on sckx. when the last bit is latched, the sspxif interrupt flag bit is set. while in slave mode, the external clock is supplied by the external clock source on the sckx pin. this external clock must meet the minimum high and low times as specified in the electrical specifications. while in sleep mode, the slave can transmit/receive data. when a byte is received, the device can be configured to wake-up from sleep. 20.3.8 slave select synchronization the ssx pin allows a synchronous slave mode. the spi must be in slave mode with the ssx pin control enabled (sspxcon1<3:0> = 04h). when the ssx pin is low, transmission and reception are enabled and the sdox pin is driven. when the ssx pin goes high, the sdox pin is no longer driven, even if in the middle of a transmitted byte and becomes a floating output. external pull-up/pull-down resistors may be desirable depending on the application. when the spi module resets, the bit counter is forced to ? 0 ?. this can be done by either forcing the ssx pin to a high level or clearing the sspen bit. to emulate two-wire communication, the sdox pin can be connected to the sdix pin. when the spi needs to operate as a receiver, the sdox pin can be configured as an input. this disables transmissions from the sdox. the sdix can always be left as an input (sdix function) since it cannot create a bus conflict. figure 20-4: slave synchronization waveform note: when the spi is in slave mode with ssx pin control enabled (sspxcon1<3:0> = 0100 ), the spi module will reset if the ssx pin is set to v dd . if the spi is used in slave mode with cke set, then the ssx pin control must be enabled. sckx (ckp = 1 sckx (ckp = 0 input sample sdix bit 7 sdox bit 7 bit 6 bit 7 sspxif interrupt (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspxbuf sspxsr to sspxbuf ssx flag bit 0 bit 7 bit 0 next q4 cycle after q2 ?
pic18f97j94 family ds30575a-page 360 ? 2012 microchip technology inc. figure 20-5: spi mode waveform (slave mode with cke = 0 ) figure 20-6: spi mode waveform (slave mode with cke = 1 ) sckx (ckp = 1 sckx (ckp = 0 input sample sdix bit 7 sdox bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspxif interrupt (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspxbuf sspxsr to sspxbuf ssx flag optional next q4 cycle after q2 ? bit 0 sckx (ckp = 1 sckx (ckp = 0 input sample sdix bit 7 bit 0 sdox bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspxif interrupt (smp = 0 ) cke = 1 ) cke = 1 ) (smp = 0 ) write to sspxbuf sspxsr to sspxbuf ssx flag not optional next q4 cycle after q2 ?
? 2012 microchip technology inc. ds30575a-page 361 pic18f97j94 family 20.3.9 operation in power-managed modes in spi master mode, module clocks may be operating at a different speed than when in full-power mode. in the case of sleep mode, all clocks are halted. in idle modes, a clock is provided to the peripherals. that clock can be from the primary clock source, the secondary clock (sosc oscillator) or the intosc source. in most cases, the speed that the master clocks spi data is not important; however, this should be evaluated for each system. if msspx interrupts are enabled, they can wake the controller from sleep mode, or one of the idle modes, when the master completes sending data. if an exit from sleep or idle mode is not desired, msspx interrupts should be disabled. if the sleep mode is selected, all module clocks are halted and the transmission/reception will remain in that state until the device wakes. after the device returns to run mode, the module will resume transmitting and receiving data. in spi slave mode, the spi transmit/receive shift register operates asynchronously to the device. this allows the device to be placed in any power-managed mode and data to be shifted into the spi transmit/ receive shift register. when all 8 bits have been received, the msspx interrupt flag bit will be set, and if enabled, will wake the device. 20.3.10 effects of a reset a reset disables the msspx module and terminates the current transfer. 20.3.11 bus mode compatibility table 20-1 shows the compatibility between the standard spi modes and the states of the ckp and cke control bits. table 20-1: spi bus modes there is also an smp bit which controls when the data is sampled. 20.3.12 spi clock speed and module interactions because mssp1 and mssp2 are independent modules, they can operate simultaneously at different data rates. setting the sspm<3:0> bits of the sspxcon1 register determines the rate for the corresponding module. an exception is when both modules use timer2 as a time base in master mode. in this instance, any changes to the timer2 module?s operation will affect both msspx modules equally. if different bit rates are required for each module, the user should select one of the other three time base options for one of the modules. standard spi mode terminology control bits state ckp cke 0 , 001 0 , 100 1 , 011 1 , 110
pic18f97j94 family ds30575a-page 362 ? 2012 microchip technology inc. 20.4 spi dma module the spi dma module contains control logic to allow the mssp1 module to perform spi direct memory access transfers. this enables the module to quickly transmit or receive large amounts of data with relatively little cpu intervention. when the spi dma module is used, mssp1 can directly read and write to general purpose sram. when the spi dma module is not enabled, mssp1 functions normally, but without dma capability. the spi dma module is composed of control logic, a destination receive address pointer, a transmit source address pointer, an interrupt manager and a byte count register for setting the size of each dma transfer. the dma module may be used with all spi master and slave modes, and supports both half-duplex and full-duplex transfers. 20.4.1 i/o pin considerations when enabled, the spi dma module uses the mssp1 module. all spi input and output signals, related to mssp1, are routed through the peripheral pin select (pps) module. the appropriate initialization procedure, as described in section 20.4.6 ?using the spi dma module? , will need to be followed prior to using the spi dma module. the output pins assigned to the sdo and sck functions can optionally be configured as open-drain outputs, such as for level shifting operations mentioned in the same section. 20.4.2 ram to ram copy operations although the spi dma module is primarily intended to be used for spi communication purposes, the module can also be used to perform ram to ram copy opera- tions. to do this, configure the module for full-duplex master mode operation, but assign the sdo output and sdi input functions onto the same rpn pin in the pps- lite module. also assign sck out and sck in onto the same rpn pin (a different pin than used for sdo and sdi). this will allow the module to operate in loopback mode, providing ram copy capability. 20.4.3 idle and sleep considerations the spi dma module remains fully functional when the microcontroller is in idle mode. during normal sleep, the spi dma module is not func- tional and should not be used. to avoid corrupting a transfer, user firmware should be careful to make certain that pending dma operations are complete by polling the dmaen bit in the dmacon1 register, prior to putting the microcontroller into sleep. in spi slave modes, the mssp1 module is capable of transmitting and/or receiving one byte of data while in sleep mode. this allows the ssp1if flag in the pir1 register to be used as a wake-up source. when the dmaen bit is cleared, the spi dma module is effectively disabled, and the mssp1 module functions normally, but without dma capabilities. if the dmaen bit is clear prior to entering sleep, it is still possible to use the ssp1if as a wake-up source without any data loss. neither mssp1 nor the spi dma module will provide any functionality in deep sleep. upon exiting from deep sleep, all of the i/o pins, mssp1 and spi dma related registers will need to be fully re-initialized before the spi dma module can be used again. 20.4.4 registers the spi dma engine is enabled and controlled by the following special function registers: ? dmacon1 ? dmacon2 ? txaddrh ? txaddrl ? rxaddrh ? rxaddrl ? dmabch ? dmabcl
? 2012 microchip technology inc. ds30575a-page 363 pic18f97j94 family 20.4.4.1 dmacon1 the dmacon1 register is used to select the main operating mode of the spi dma module. the sscon1 and sscon0 bits are used to control the slave select pin. when mssp1 is used in spi master mode with the spi dma module, ssdma can be controlled by the dma module as an output pin. if mssp1 will be used to com- municate with an spi slave device that needs the ssx pin to be toggled periodically, the spi dma hardware can automatically be used to de-assert ssx between each byte, every two bytes or every four bytes. alternatively, user firmware can manually generate slave select signals with normal general purpose i/o pins, if required by the slave device(s). when the txinc bit is set, the txaddr register will automatically increment after each transmitted byte. automatic transmit address increment can be disabled by clearing the txinc bit. if the automatic transmit address increment is disabled, each byte which is out- put on sdo will be the same (the contents of the sram pointed to by the txaddr register) for the entire dma transaction. when the rxinc bit is set, the rxaddr register will automatically increment after each received byte. automatic receive address increment can be disabled by clearing the rxinc bit. if rxinc is disabled in full- duplex or half-duplex receive modes, all incoming data bytes on sdi will overwrite the same memory location pointed to by the rxaddr register. after the spi dma transaction has completed, the last received byte will reside in the memory location pointed to by the rxaddr register. the spi dma module can be used for either half-duplex receive only communication, half-duplex transmit only communication or full-duplex simultaneous transmit and receive operations. all modes are available for both spi master and spi slave configurations. the duplex0 and duplex1 bits can be used to select the desired operating mode. the behavior of the dlyinten bit varies greatly depending on the spi operating mode. for example behavior for each of the modes, see figure 20-3 through figure 20-6 . spi slave mode, dlyinten = 1 : in this mode, an ssp1if interrupt will be generated during a transfer if the time between successful byte transmission events is longer than the value set by the dlycyc<3:0> bits in the dmacon2 register. this interrupt allows slave firmware to know that the master device is taking an unusually large amount of time between byte transmis- sions. for example, this information may be useful for implementing application defined communication protocols, involving time-outs if the bus remains idle for too long. when dlyinten = 1 , the dlylvl<3:0> interrupts occur normally according to the selected setting. spi slave mode, dlyinten = 0 : in this mode, the time-out based interrupt is disabled. no additional ssp1if interrupt events will be generated by the spi dma module, other than those indicated by the intlvl<3:0> bits in the dmacon2 register. in this mode, always set dlycyc<3:0> = 0000 . spi master mode, dlyinten = 0 : the dlycyc<3:0> bits in the dmacon2 register determine the amount of additional inter-byte delay, which is added by the spi dma module during a transfer; the master mode ss1 output feature may be used. spi master mode, dlyinten = 1 : the amount of hardware overhead is slightly reduced in this mode, and the minimum inter-byte delay is 8 t cy for f osc /4, 9 t cy for f osc /16 and 15 t cy for f osc /64. this mode can potentially be used to obtain slightly higher effec- tive spi bandwidth. in this mode, the ss1 control feature cannot be used and should always be disabled (dmacon1<7:6> = 00 ). additionally, the interrupt generating hardware (used in slave mode) remains active. to avoid extraneous ssp1if interrupt events, set the dmacon2 delay bits, dlycyc<3:0> = 1111 , and ensure that the spi serial clock rate is no slower than f osc /64. in spi master modes, the dmaen bit is used to enable the spi dma module and to initiate an spi dma trans- action. after user firmware sets the dmaen bit, the dma hardware will begin transmitting and/or receiving data bytes according to the configuration used. in spi slave modes, setting the dmaen bit will finish the initialization steps needed to prepare the spi dma module for communication (which must still be initiated by the master device). to avoid possible data corruption, once the dmaen bit is set, user firmware should not attempt to modify any of the mssp2 or spi dma related registers, with the exception of the intlvlx bits in the dmacon2 register. if user firmware wants to halt an ongoing dma transac- tion, the dmaen bit can be manually cleared by the firmware. clearing the dmaen bit while a byte is currently being transmitted will not immediately halt the byte in progress. instead, any byte currently in progress will be completed before the mssp1 and spi dma modules go back to their idle conditions. if user firmware clears the dmaen bit, the txaddr, rxaddr and dmabc registers will no longer update, and the dma module will no longer make any additional read or writes to sram; therefore, state information can be lost.
pic18f97j94 family ds30575a-page 364 ? 2012 microchip technology inc. register 20-4: dmacon1: dma control register 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 sscon1 sscon0 txinc rxinc duplex1 duplex0 dlyinten dmaen bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 sscon<1:0>: ssdma output control bits (master modes only) 11 = ssdma is asserted for the duration of 4 bytes; dlyinten is always reset low 01 = ssdma is asserted for the duration of 2 bytes; dlyinten is always reset low 10 = ssdma is asserted for the duration of 1 byte; dlyinten is always reset low 00 = ssdma is not controlled by the dma module; dlyinten bit is software programmable bit 5 txinc: transmit address increment enable bit allows the transmit address to increment as the transfer progresses. 1 = the transmit address is to be incremented from the initial value of txaddr<11:0> 0 = the transmit address is always set to the initial value of txaddr<11:0> bit 4 rxinc: receive address increment enable bit allows the receive address to increment as the transfer progresses. 1 = the received address is to be incremented from the initial value of rxaddr<11:0> 0 = the received address is always set to the initial value of rxaddr<11:0> bit 3-2 duplex<1:0>: transmit/receive operating mode select bits 10 = spi dma operates in full-duplex mode, data is simultaneously transmitted and received 01 = dma operates in half-duplex mode, data is transmitted only 00 = dma operates in half-duplex mode, data is received only bit 1 dlyinten: delay interrupt enable bit enables the interrupt to be invoked after the number of t cy cycles, specified in dlycyc<3:0>, has elapsed from the latest completed transfer. 1 = the interrupt is enabled, sscon<1:0> must be set to ? 00 ? 0 = the interrupt is disabled bit 0 dmaen: dma operation start/stop bit this bit is set by the users? software to start the dma operation. it is reset back to zero by the dma engine when the dma operation is completed or aborted. 1 = dma is in session 0 = dma is not in session
? 2012 microchip technology inc. ds30575a-page 365 pic18f97j94 family 20.4.4.2 dmacon2 the dmacon2 register contains control bits for controlling interrupt generation and inter-byte delay behavior. the intlvl<3:0> bits are used to select when an ssp1if interrupt should be generated. the function of the dlycyc<3:0> bits depends on the spi operating mode (master/slave), as well as the dlyinten setting. in spi master mode, the dlycyc<3:0> bits can be used to control how much time the module will idle between bytes in a transfer. by default, the hardware requires a minimum delay of 8t cy for f osc /4, 9 t cy for f osc /16 and 15 t cy for f osc /64. an additional delay can be added with the dlycycx bits. in spi slave modes, the dlycyc<3:0> bits may optionally be used to trigger an additional time-out based interrupt. register 20-5: dmacon2: dma control register 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 dlycyc3 dlycyc2 dlycyc1 dlycyc0 intlvl3 intlvl2 intlvl1 intlvl0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 dlycyc<3:0>: delay cycle selection bits when dlyinten = 0 , these bits specify the additional delay (above the base overhead of the hard- ware), in number of t cy cycles, before the ssp2buf register is written again for the next transfer. when dlyinten = 1 , these bits specify the delay in number of t cy cycles from the latest completed transfer before an interrupt to the cpu is invoked. in this case, the additional delay before the ssp2buf register is written again is 1 t cy + (base overhead of hardware). 1111 = delay time in number of instruction cycles is 2,048 cycles 1110 = delay time in number of instruction cycles is 1,024 cycles 1101 = delay time in number of instruction cycles is 896 cycles 1100 = delay time in number of instruction cycles is 768 cycles 1011 = delay time in number of instruction cycles is 640 cycles 1010 = delay time in number of instruction cycles is 512 cycles 1001 = delay time in number of instruction cycles is 384 cycles 1000 = delay time in number of instruction cycles is 256 cycles 0111 = delay time in number of instruction cycles is 128 cycles 0110 = delay time in number of instruction cycles is 64 cycles 0101 = delay time in number of instruction cycles is 32 cycles 0100 = delay time in number of instruction cycles is 16 cycles 0011 = delay time in number of instruction cycles is 8 cycles 0010 = delay time in number of instruction cycles is 4 cycles 0001 = delay time in number of instruction cycles is 2 cycles 0000 = delay time in number of instruction cycles is 1 cycle
pic18f97j94 family ds30575a-page 366 ? 2012 microchip technology inc. bit 3-0 intlvl<3:0>: watermark interrupt enable bits these bits specify the amount of remaining data yet to be transferred (transmitted and/or received) upon which an interrupt is generated. 1111 = amount of remaining data to be transferred is 576 bytes 1110 = amount of remaining data to be transferred is 512 bytes 1101 = amount of remaining data to be transferred is 448 bytes 1100 = amount of remaining data to be transferred is 384 bytes 1011 = amount of remaining data to be transferred is 320 bytes 1010 = amount of remaining data to be transferred is 256 bytes 1001 = amount of remaining data to be transferred is 192 bytes 1000 = amount of remaining data to be transferred is 128 bytes 0111 = amount of remaining data to be transferred is 67 bytes 0110 = amount of remaining data to be transferred is 32 bytes 0101 = amount of remaining data to be transferred is 16 bytes 0100 = amount of remaining data to be transferred is 8 bytes 0011 = amount of remaining data to be transferred is 4 bytes 0010 = amount of remaining data to be transferred is 2 bytes 0001 = amount of remaining data to be transferred is 1 byte 0000 = transfer complete register 20-5: dmacon2: dma control register 2 (continued)
? 2012 microchip technology inc. ds30575a-page 367 pic18f97j94 family 20.4.4.3 dmabch and dmabcl the dmabch and dmabcl register pair forms a 10-bit byte count register, which is used by the spi dma module to send/receive up to 1,024 bytes for each dma transaction. when the dma module is actively running (dmaen = 1 ), the dma byte count register dec- rements after each byte is transmitted/received. the dma transaction will halt and the dmaen bit will be automatically cleared by hardware after the last byte has completed. after a dma transaction is complete, the dmabc register will read 0x000. prior to initiating a dma transaction by setting the dmaen bit, user firmware should load the appropriate value into the dmabch/dmabcl registers. the dmabc is a ?base zero? counter, so the actual number of bytes which will be transmitted follows in equation 20-1 . for example, if user firmware wants to transmit 7 bytes in one transaction, dmabc should be loaded with 006h. similarly, if user firmware wishes to transmit 1,024 bytes, dmabc should be loaded with 3ffh. equation 20-1: bytes transmitted for a given dmabc 20.4.4.4 txaddrh and txaddrl the txaddrh and txaddrl registers pair together to form a 12-bit transmit source address pointer register. in modes that use txaddr (full-duplex and half-duplex transmit), the txaddr will be incre- mented after each byte is transmitted. transmitted data bytes will be taken from the memory location pointed to by the txaddr register. the contents of the memory locations pointed to by txaddr will not be modified by the dma module during a transmission. the spi dma module can read from, and transmit data from, all general purpose memory on the device, includ- ing memory used for usb endpoint buffers. the spi dma module cannot be used to read from the special function registers (sfrs) contained in banks 14 and 15. 20.4.4.5 rxaddrh and rxaddrl the rxaddrh and rxaddrl registers pair together to form a 12-bit receive destination address pointer. in modes that use rxaddr (full-duplex and half- duplex receive), the rxaddr register will be incremented after each byte is received. received data bytes will be stored at the memory location pointed to by the rxaddr register. bytes xmit dmabc 1 + ?? ?
pic18f97j94 family ds30575a-page 368 ? 2012 microchip technology inc. the spi dma module can write received data to all general purpose memory on the device, including memory used for usb endpoint buffers. the spi dma module cannot be used to modify the special function registers contained in banks 14 and 15. 20.4.5 interrupts the spi dma module alters the behavior of the ssp1if interrupt flag. in normal non-dma modes, the ssp1if is set once after every single byte is transmit- ted/received through the mssp1 module. when mssp1 is used with the spi dma module, the ssp1if interrupt flag will be set according to the user-selected intlvl<3:0> value specified in the dmacon2 register. the ssp1if interrupt condition will also be generated once the spi dma transaction has fully completed and the dmaen bit has been cleared by hardware. the ssp1if flag becomes set once the dma byte count value indicates that the specified intlvlx has been reached. for example, if dmacon2<3:0> = 0101 (16 bytes remaining), the ssp1if interrupt flag will become set once dmabc reaches 00fh. if user firmware then clears the ssp1if interrupt flag, the flag will not be set again by the hardware until after all bytes have been fully transmitted and the dma transaction is complete. for example, if dmabc = 00fh (implying 16 bytes are remaining) and user firmware writes ? 1111 ? to intlvl<3:0> (interrupt when 576 bytes are remaining), the ssp1if interrupt flag will immediately become set. if user firmware clears this interrupt flag, a new inter- rupt condition will not be generated until either: user firmware again writes intlvlx with an interrupt level higher than the actual remaining level, or the dma transaction completes and the dmaen bit is cleared. note: user firmware may modify the intlvlx bits while a dma transaction is in progress (dmaen = 1 ). if an intlvlx value is selected which is higher than the actual remaining number of bytes (indicated by dmabc + 1 ), the ssp1if interrupt flag will immediately become set. note: if the intlvlx bits are modified while a dma transaction is in progress, care should be taken to avoid inadvertently changing the dlycyc<3:0> value.
? 2012 microchip technology inc. ds30575a-page 369 pic18f97j94 family 20.4.6 using the spi dma module the following steps would typically be taken to enable and use the spi dma module: 1. configure the i/o pins, which will be used by mssp2: a) assign sck1, sdo1, sdi1 and ss1 to the rpn pins, as appropriate for the spi mode which will be used. only functions which will be used need to be assigned to a pin. b) initialize the associated latx registers for the desired idle spi bus state. c) if open-drain output mode on sdo1 and sck1 (master mode) is desired, set odcon1<1>. d) configure the corresponding trisx bits for each i/o pin used. 2. configure and enable mssp1 for the desired spi operating mode: a) select the desired operating mode (master or slave, spi mode 0, 1, 2 and 3) and con- figure the module by writing to the ssp1stat and ssp1con1 registers. b) enable mssp1 by setting ssp1con1<5> = 1 . 3. configure the spi dma engine: a) select the desired operating mode by writing the appropriate values to dmacon2 and dmacon1. b) initialize the txaddrh/txaddrl pointer (full-duplex or half-duplex transmit only mode). c) initialize the rxaddrh/rxaddrl pointer (full-duplex or half-duplex receive only mode). d) initialize the dmabch/dmabcl byte count register with the number of bytes to be transferred in the next spi dma operation. e) set the dmaen bit (dmacon1<0>). in spi master modes, this will initiate a dma transaction. in spi slave modes, this will com- plete the initialization process, and the module will now be ready to begin receiving and/or transmitting data to the master device once the master starts the transaction. 4. detect the ssp1if interrupt condition (pir1<3): a) if the interrupt was configured to occur at the completion of the spi dma transaction, the dmaen bit (dmacon1<0>) will be clear. user firmware may prepare the module for another transaction by repeating steps 3.b through 3.e . b) if the interrupt was configured to occur prior to the completion of the spi dma trans- action, the dmaen bit may still be set, indicating the transaction is still in progress. user firmware would typically use this inter- rupt condition to begin preparing new data for the next dma transaction. firmware should not repeat steps 3.b . through 3.e . until the dmaen bit is cleared by the hardware, indicating the transaction is complete. example 20-3 provides example code, demonstrating the initialization process and the steps needed to use the spi dma module to perform a 512-byte full-duplex master mode transfer.
pic18f97j94 family ds30575a-page 370 ? 2012 microchip technology inc. example 20-2: 512-byte spi master mode init and transfer ;for this example, let's use rp3(ra3) for sck1, ;rp1(ra1) for sdo1, and rp0(ra0) for sdi1 ;let?s use spi master mode, cke = 0, ckp = 0, ;without using slave select signalling. initspipins: movlb 0x0e ;select bank 14, for access to odcon1 register bcf odcon1, ssp1_od ;let?s not use open drain outputs in this example bcf lata, ra3 ;initialize our (to be) sck1 pin low (idle). bcf lata, ra1 ;initialize our (to be) sdo1 pin to an idle state bcf trisa, ra1 ;make sdo1 output, and drive low bcf trisa, ra3 ;make sck1 output, and drive low (idle state) bsf trisa, ra0 ;sdi2 is an input, make sure it is tri-stated ;now we should unlock the pps-lite registers, so we can ;assign the mssp2 functions to our desired i/o pins. movlb 0x0f ;select bank 15 for access to pps-lite registers bcf intcon, gie ;i/o pin unlock sequence will not work if cpu ;services an interrupt during the sequence movlw 0x55 ;unlock sequence consists of writing 0x55 movwf eecon2 ;and 0xaa to the eecon2 register. movlw 0xaa movwf eecon2 bcf osccon2, iolock ;we may now write to rpinrx and rporx registers bsf intcon, gie ;may now turn back on interrupts if desired movlw 0x00 ;rp0 will be sdi1 movwf rpinr8-9 ;assign the sdi1 function to pin rp0 movlw 0x30 ;let?s assign sck1 output to pin rp3 movwf rpor2_3 ;rpor2_3 maps output signals to rp3 pin movlw 0x00 ; sck1 also needs to be configured as an input on the same pin movwf rpinr8_9 ;sck1 input function taken from rp3 pin movlw 0x40 ;0x40 is sdo1 output movwf rpor0_1 ;assign sdo1 output signal to the rp1 (ra1) pin movlb 0x0f ;done with pps-lite registers, bank 15 has other sfrs initmssp2: clrf ssp1stat ;cke = 0, smp = 0 (sampled at middle of bit) movlw b'00000000' ;ckp = 0, spi master mode, fosc/4 movwf ssp1con1 ;mssp2 initialized bsf ssp1con1, sspen ;enable the mssp2 module initspidma: movlw b'00111010' ;full duplex, rx/txinc enabled, no sscon movwf dmacon1 ;dlyinten is set, so dlycyc3:dlycyc0 = 1111 movlw b'11110000' ;minimum delay between bytes, interrupt movwf dmacon2 ;only once when the transaction is complete ;somewhere else in our project, lets assume we have ;allocated some ram for use as spi receive and ;transmit buffers.
? 2012 microchip technology inc. ds30575a-page 371 pic18f97j94 family ; udata 0x500 ;destbuf res 0x200 ;let?s reserve 0x500-0x6ff for use as our spi ; ;receive data buffer in this example ;srcbuf res 0x200 ;lets reserve 0x700-0x8ff for use as our spi ; ;transmit data buffer in this example preparetransfer: movlw high(destbuf) ;get high byte of destbuf address (0x05) movwf rxaddrh ;load upper four bits of the rxaddr register movlw low(destbuf) ;get low byte of the destbuf address (0x00) movwf rxaddrl ;load lower eight bits of the rxaddr register movlw high(srcbuf) ;get high byte of srcbuf address (0x07) movwf txaddrh ;load upper four bits of the txaddr register movlw low(srcbuf) ;get low byte of the srcbuf address (0x00) movwf txaddrl ;load lower eight bits of the txaddr register movlw 0x01 ;lets move 0x200 (512) bytes in one dma xfer movwf dmabch ;load the upper two bits of dmabc register movlw 0xff ;actual bytes transferred is (dmabc + 1), so movwf dmabcl ;we load 0x01ff into dmabc to xfer 0x200 bytes beginxfer: bsf dmacon1, dmaen ;the spi dma module will now begin transferring ;the data taken from srcbuf, and will store ;received bytes into destbuf. ;execute whatever ;cpu is now free to do whatever it wants to ;and the dma operation will continue without ;intervention, until it completes. ;when the transfer is complete, the ssp2if flag in ;the pir3 register will become set, and the dmaen bit ;is automatically cleared by the hardware. ;the destbuf (0x500-0x7ff) will contain the received ;data. to start another transfer, firmware will need ;to reinitialize rxaddr, txaddr, dmabc and then ;set the dmaen bit. example 20-2: 512-byte spi master mode init and transfer (continued)
pic18f97j94 family ds30575a-page 372 ? 2012 microchip technology inc. 20.5 i 2 c mode the msspx module in i 2 c? mode fully implements all master and slave functions (including general call support), and provides interrupts on start and stop bits in hardware to determine a free bus (multi-master function). the msspx module implements the standard mode specifications, as well as 7-bit and 10-bit addressing. two pins are used for data transfer: ? serial clock (sclx) ? rc3/scl1 or rd6/scl2 ? serial data (sdax) ? rc4/sda1 or rd5/sda2 the user must configure these pins as inputs by setting the associated tris bits. figure 20-7: msspx block diagram (i 2 c? mode) 20.5.1 registers the msspx module has seven registers for i 2 c operation. these are: ? msspx control register 1 (sspxcon1) ? msspx control register 2 (sspxcon2) ? msspx control register 3 (sspxcon3) ? msspx status register (sspxstat) ? serial receive/transmit buffer register (sspxbuf) ? msspx shift register (sspxsr) ? not directly accessible ? msspx address register (sspxadd) ?i 2 c slave address mask register (sspxmsk) sspxcon1, sspxcon2, sspxcon3 and sspxstat are the control and status registers in i 2 c mode opera- tion. the sspxcon1, sspxcon2, and sspxcon3 registers are readable and writable. the lower 6 bits of the sspxstat are read-only. the upper two bits of the sspxstat are read/write. sspxsr is the shift register used for shifting data in or out. sspxbuf is the buffer register to which data bytes are written to or read from. sspxadd contains the slave device address when the msspx is configured in i 2 c slave mode. when the msspx is configured in master mode, the lower seven bits of sspxadd act as the baud rate generator reload value. sspxmsk holds the slave address mask value when the module is configured for 7-bit address masking mode. while it is a separate register, it shares the same sfr address as sspxadd; it is only accessible when the sspm<3:0> bits are specifically set to permit access. additional details are provided in section 20.5.4.3 ?7-bit address masking mode? . in receive operations, sspxsr and sspxbuf together, create a double-buffered receiver. when sspxsr receives a complete byte, it is transferred to sspxbuf and the sspxif interrupt is set. during transmission, the sspxbuf is not double- buffered. a write to sspxbuf will write to both sspxbuf and sspxsr. read write match detect sspxadd reg sspxbuf reg internal data bus addr match set, reset s, p bits (sspxstat reg) shift clock msb lsb note: only port i/o names are used in this diagram for the sake of brevity. refer to the text for a full list of multiplexed functions. sckx sdix start and stop bit detect address mask sspxsr reg
? 2012 microchip technology inc. ds30575a-page 373 pic18f97j94 family register 20-6: sspxstat: msspx status register (i 2 c? mode) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke d/a p ( 1 ) s ( 1 ) r/w ( 2 , 3 ) ua bf bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 smp: slew rate control bit in master or slave mode: 1 = slew rate control is disabled for standard speed mode (100 khz and 1 mhz) 0 = slew rate control is enabled for high-speed mode (400 khz) bit 6 cke: smbus select bit in master or slave mode: 1 = enables smbus-specific inputs 0 = disables smbus-specific inputs bit 5 d/a : data/address bit in master mode: reserved. in slave mode: 1 = indicates that the last byte received or transmitted was data 0 = indicates that the last byte received or transmitted was address bit 4 p: stop bit ( 1 ) 1 = indicates that a stop bit has been detected last 0 = stop bit was not detected last bit 3 s: start bit ( 1 ) 1 = indicates that a start bit has been detected last 0 = start bit was not detected last bit 2 r/w : read/write information bit ( 2 , 3 ) in slave mode: 1 = read 0 = write in master mode: 1 = transmit is in progress 0 = transmit is not in progress bit 1 ua: update address bit (10-bit slave mode only) 1 = indicates that the user needs to update the address in the sspxadd register 0 = address does not need to be updated bit 0 bf: buffer full status bit in transmit mode: 1 = sspxbuf is full 0 = sspxbuf is empty in receive mode: 1 = sspxbuf is full (does not include the ack and stop bits) 0 = sspxbuf is empty (does not include the ack and stop bits) note 1: this bit is cleared on reset and when sspen is cleared. 2: this bit holds the r/w bit information following the last address match. this bit is only valid from the address match to the next start bit, stop bit or not ack bit. 3: oring this bit with sen, rsen, pen, rcen or acken w ill indicate if the msspx is in active mode.
pic18f97j94 family ds30575a-page 374 ? 2012 microchip technology inc. register 20-7: sspxcon1: ms spx control register 1 (i 2 c? mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov sspen ( 1 ) ckp sspm3 ( 2 ) sspm2 ( 2 ) sspm1 ( 2 ) sspm0 ( 2 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wcol: write collision detect bit in master transmit mode: 1 = a write to the sspxbuf register was attempted while the i 2 c conditions were not valid for a transmission to be started (must be cleared in software) 0 = no collision in slave transmit mode: 1 = the sspxbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision in receive mode (master or slave modes): this is a ?don?t care? bit. bit 6 sspov: receive overflow indicator bit in receive mode: 1 = a byte is received while the sspxbuf register is still holding the previous byte (must be cleared in software) 0 = no overflow in transmit mode: this is a ?don?t care? bit in transmit mode. bit 5 sspen: master synchronous serial port enable bit ( 1 ) 1 = enables the serial port and configures the sdax and sclx pins as the serial port pins 0 = disables serial port and configures these pins as i/o port pins bit 4 ckp: sckx release control bit in slave mode: 1 = releases clock 0 = holds clock low (clock stretch), used to ensure data setup time in master mode: unused in this mode. bit 3-0 sspm<3:0>: master synchronous serial port mode select bits ( 2 ) 1111 = i 2 c slave mode: 10-bit address with start and stop bit interrupts enabled 1110 = i 2 c slave mode: 7-bit address with start and stop bit interrupts enabled 1011 = i 2 c firmware controlled master mode (slave idle) 1001 = load sspxmsk register at sspxadd sfr address ( 3 , 4 ) 1000 = i 2 c master mode: clock = f osc /(4 * (sspxadd + 1)) 0111 = i 2 c slave mode: 10-bit address ( 3 , 4 ) 0110 = i 2 c slave mode: 7-bit address note 1: when enabled, the sdax and sclx pins must be configured as inputs. 2: bit combinations not specifically listed here are either reserved or implemented in spi mode only. 3: when sspm<3:0> = 1001 , any reads or writes to the sspxadd sfr address actually accesses the sspxmsk register. 4: this mode is only available when 7-bit address masking mode is selected (msspmsk configuration bit is ? 1 ?).
? 2012 microchip technology inc. ds30575a-page 375 pic18f97j94 family register 20-8: sspxcon2: msspx control register 2 (i 2 c? master mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 gcen ackstat ackdt ( 1 ) acken ( 2 ) rcen ( 2 ) pen ( 2 ) rsen ( 2 ) sen ( 2 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 gcen: general call enable bit unused in master mode. bit 6 ackstat: acknowledge status bit (master transmit mode only) 1 = acknowledge was not received from slave 0 = acknowledge was received from slave bit 5 ackdt: acknowledge data bit (master receive mode only) ( 1 ) 1 = not acknowledge 0 = acknowledge bit 4 acken: acknowledge sequence enable bit ( 2 ) 1 = initiates acknowledge sequence on sdax and sclx pins and transmits ackdt data bit; automatically cleared by hardware 0 = acknowledge sequence is idle bit 3 rcen: receive enable bit (master receive mode only) ( 2 ) 1 = enables receive mode for i 2 c? 0 = receive is idle bit 2 pen: stop condition enable bit ( 2 ) 1 = initiates stop condition on sdax and sclx pins; automatically cleared by hardware 0 = stop condition is idle bit 1 rsen: repeated start condition enable bit ( 2 ) 1 = initiates repeated start condition on sdax and sclx pins; automatically cleared by hardware 0 = repeated start condition is idle bit 0 sen: start condition enable bit ( 2 ) 1 = initiates start condition on sdax and sclx pins; automatically cleared by hardware 0 = start condition is idle note 1: the value that will be transmitted when the user initiates an acknowledge sequence at the end of a receive. 2: if the i 2 c module is active, these bits may not be set (no spooling) and the sspxbuf may not be written (or writes to the sspxbuf are disabled).
pic18f97j94 family ds30575a-page 376 ? 2012 microchip technology inc. register 20-9: sspxcon3: m ssp control register 3 (i 2 c master mode) r/hs/hc-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 acktim pcie scie boen sdaht sbcde ahen dhen bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 acktim: acknowledge time status bit unused in master mode. bit 6 pcie: stop condition interrupt enable bit ( 1 ) 1 = enable interrupt on detection of stop condition 0 = stop detection interrupts are disabled bit 5 scie: start condition interrupt enable bit ( 1 ) 1 = enable interrupt on detection of start or restart conditions 0 = start detection interrupts are disabled bit 4 boen: buffer overwrite enable bit 1 = sspbuf is updated every time a new data byte is available, ignoring the sspov effect on updating the buffer 0 = sspbuf is only updated when sspov is clear bit 3 sdaht: sda hold time selection bit 1 = minimum of 300ns hold time on sda after the falling edge of scl 0 = minimum of 100ns hold time on sda after the falling edge of scl bit 2 sbcde: slave mode bus collision detect enable bit unused in master mode. bit 1 ahen: address hold enable bit unused in master mode. bit 0 dhen: data hold enable bit unused in master mode. note 1: this bit has no effect in slave modes that start and stop condition detection is explicitly listed as enabled.
? 2012 microchip technology inc. ds30575a-page 377 pic18f97j94 family register 20-10: sspxcon2: msspx control register 2 (i 2 c? slave mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 gcen ackstat ackdt ( 1 ) acken ( 1 ) rcen ( 1 ) pen ( 1 ) rsen ( 1 ) sen ( 1 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 gcen: general call enable bit 1 = enables interrupt when a general call address (0000h) is received in the sspxsr 0 = general call address is disabled bit 6 ackstat: acknowledge status bit unused in slave mode. bit 5 ackdt: acknowledge data bit (master receive mode only) ( 1 ) 1 = not acknowledge 0 = acknowledge bit 4 acken: acknowledge sequence enable bit ( 1 ) 1 = initiates acknowledge sequence on sdax and sclx pins and transmits ackdt data bit; automatically cleared by hardware 0 = acknowledge sequence is idle bit 3 rcen: receive enable bit (master receive mode only) ( 1 ) 1 = enables receive mode for i 2 c 0 = receive is idle bit 2 pen: stop condition enable bit ( 1 ) 1 = initiates stop condition on sdax and sclx pins; automatically cleared by hardware 0 = stop condition is idle bit 1 rsen: repeated start condition enable bit ( 1 ) 1 = initiates repeated start condition on sdax and sclx pins; automatically cleared by hardware 0 = repeated start condition is idle bit 0 sen: stretch enable bit ( 1 ) 1 = clock stretching is enabled for both slave transmit and slave receive (stretch enabled) 0 = clock stretching is disabled note 1: if the i 2 c module is active, this bit may not be set (no spooling) and the sspxbuf may not be written (or writes to the sspxbuf are disabled).
pic18f97j94 family ds30575a-page 378 ? 2012 microchip technology inc. register 20-11: sspxcon3: m ssp control register 3 (i 2 c slave mode) r/hs/hc-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 acktim pcie scie boen sdaht sbcde ahen dhen bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 acktim: acknowledge time status bit 1 = indicates the i 2 c bus is in an acknowledge sequence, set on 8th falling edge of scl clock 0 = not an acknowledge sequence, cleared on 9th rising edge of scl clock bit 6 pcie: stop condition interrupt enable bit ( 1 ) 1 = enable interrupt on detection of stop condition 0 = stop detection interrupts are disabled bit 5 scie: start condition interrupt enable bit ( 1 ) 1 = enable interrupt on detection of start or restart conditions 0 = start detection interrupts are disabled bit 4 boen: buffer overwrite enable bit 1 = sspbuf is updated every time a new data byte is available, ignoring the sspov effect on updating the buffer 0 = sspbuf is only updated when sspov is clear bit 3 sdaht: sda hold time selection bit 1 = minimum of 300ns hold time on sda after the falling edge of scl 0 = minimum of 100ns hold time on sda after the falling edge of scl bit 2 sbcde: slave mode bus collision detect enable bit if, on the rising edge of scl, sda is sampled low when the module is outputting a high state, the bclif bit is set, and bus goes idle. 1 = enable slave bus collision interrupts 0 = slave bus collision interrupts are disabled bit 1 ahen: address hold enable bit 1 = following the 8th falling edge of scl for a matching received address byte; ckp bit of sspxcon1 will be cleared and the scl will be held low. 0 = address holding is disabled bit 0 dhen: data hold enable bit 1 = following the 8th falling edge of scl for a received data byte; slave hardware clears the ckp bit of sspcon register and scl is held low. 0 = data holding is disabled note 1: this bit has no effect in slave modes that start and stop condition detection is explicitly listed as enabled.
? 2012 microchip technology inc. ds30575a-page 379 pic18f97j94 family register 20-12: sspxmsk: msspx i 2 c? slave address mask register (7-bit masking mode) ( 1 ) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 ( 2 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 msk<7:0>: slave address mask select bits 1 = masking of corresponding bit of sspxadd is enabled 0 = masking of corresponding bit of sspxadd is disabled note 1: this register shares the same sfr address as sspxadd and is only addressable in select msspx operating modes. see section 20.5.4.3 ?7-bit address masking mode? for more details. 2: msk0 is not used as a mask bit in 7-bit addressing.
pic18f97j94 family ds30575a-page 380 ? 2012 microchip technology inc. 20.5.2 operation the msspx module functions are enabled by setting the msspx enable bit, sspen (sspxcon1<5>). the sspxcon1 register allows control of the i 2 c oper- ation. four mode selection bits (sspxcon1<3:0>) allow one of the following i 2 c modes to be selected: ?i 2 c master mode, clock ?i 2 c slave mode (7-bit address) ?i 2 c slave mode (10-bit address) ?i 2 c slave mode (7-bit address) with start and stop bit interrupts enabled ?i 2 c slave mode (10-bit address) with start and stop bit interrupts enabled ?i 2 c firmware controlled master mode, slave is idle selection of any i 2 c mode, with the sspen bit set, forces the sclx and sdax pins to be open-drain, pro- vided these pins are programmed as inputs by setting the appropriate trisc or trisd bits. to ensure proper operation of the module, pull-up resistors must be provided externally to the sclx and sdax pins. 20.5.3 slave mode in slave mode, the sclx and sdax pins must be configured as inputs (trisc<4:3> set). the msspx module will override the input state with the output data when required (slave-transmitter). the i 2 c slave mode hardware will always generate an interrupt on an address match. address masking will allow the hardware to generate an interrupt for more than one address (up to 31 in 7-bit addressing and up to 63 in 10-bit addressing). through the mode select bits, the user can also choose to interrupt on start and stop bits. when an address is matched, or the data transfer after an address match is received, the hardware auto- matically will generate the acknowledge (ack ) pulse and load the sspxbuf register with the received value currently in the sspxsr register. any combination of the following conditions will cause the msspx module not to give this ack pulse: ? the buffer full bit, bf (sspxstat<0>), was set before the transfer was received. ? the overflow bit, sspov (sspxcon1<6>), was set before the transfer was received. in this case, the sspxsr register value is not loaded into the sspxbuf, but bit, sspxif, is set. the bf bit is cleared by reading the sspxbuf register, while bit, sspov, is cleared through software. the sclx clock input must have a minimum high and low for proper operation. the high and low times of the i 2 c specification, as well as the requirement of the msspx module, are shown in timing parameter 100 and parameter 101 . 20.5.4 addressing once the msspx module has been enabled, it waits for a start condition to occur. following the start condition, the 8 bits are shifted into the sspxsr register. all incoming bits are sampled with the rising edge of the clock (sclx) line. the value of register, sspxsr<7:1>, is compared to the value of the sspxadd register. the address is compared on the falling edge of the eighth clock (sclx) pulse. if the addresses match, and the bf and sspov bits are clear, the following events occur: 1. the sspxsr register value is loaded into the sspxbuf register. 2. the buffer full bit, bf, is set. 3. an ack pulse is generated. 4. the msspx interrupt flag bit, sspxif, is set (and interrupt is generated if enabled) on the falling edge of the ninth sclx pulse. in 10-bit addressing mode, two address bytes need to be received by the slave. the five most significant bits (msbs) of the first address byte specify if this is a 10-bit address. the r/w (sspxstat<2>) bit must specify a write so the slave device will receive the second address byte. for a 10-bit address, the first byte would equal ? 11110 a9 a8 0 ?, where ? a9 ? and ? a8 ? are the two msbs of the address. the sequence of events for 10-bit addressing is as follows, with steps 7 through 9 for the slave-transmitter: 1. receive first (high) byte of address (bits, sspxif, bf and ua, are set on address match). 2. update the sspxadd register with second (low) byte of address (clears bit, ua, and releases the sclx line). 3. read the sspxbuf register (clears bit, bf) and clear flag bit, sspxif. 4. receive second (low) byte of address (bits, sspxif, bf and ua, are set). 5. update the sspxadd register with the first (high) byte of address. if match releases sclx line, this will clear bit, ua. 6. read the sspxbuf register (clears bit, bf) and clear flag bit sspxif. 7. receive repeated start condition. 8. receive first (high) byte of address (bits, sspxif and bf, are set). 9. read the sspxbuf register (clears bit, bf) and clear flag bit, sspxif.
? 2012 microchip technology inc. ds30575a-page 381 pic18f97j94 family 20.5.4.1 address masking modes masking an address bit causes that bit to become a ?don?t care?. when one address bit is masked, two addresses will be acknowledged and cause an inter- rupt. it is possible to mask more than one address bit at a time, which greatly expands the number of addresses acknowledged. the i 2 c slave behaves the same way, whether address masking is used or not. however, when address mask- ing is used, the i 2 c slave can acknowledge multiple addresses and cause interrupts. when this occurs, it is necessary to determine which address caused the interrupt by checking the sspxbuf. the pic18f97j94 family of devices is capable of using two different address masking modes in i 2 c slave operation: 5-bit address masking and 7-bit address masking. the masking mode is selected at device con- figuration using the msspmsk<2:1> configuration bits. the default device configuration is 7-bit address masking. both masking modes, in turn, support address masking of 7-bit and 10-bit addresses. the combination of masking modes and addresses provides different ranges of acknowledgable addresses for each combination. while both masking modes function in roughly the same manner, the way they use address masks are different. 20.5.4.2 5-bit address masking mode as the name implies, 5-bit address masking mode uses an address mask of up to 5 bits to create a range of addresses to be acknowledged, using bits, 5 through 1, of the incoming address. this allows the module to acknowledge up to 31 addresses when using 7-bit addressing, or 63 addresses with 10-bit addressing (see example 20-3 ). this masking mode is selected when the msspmsk<2:1> configuration bits are programmed (? 00 ?). the address mask in this mode is stored in the sspxcon2 register, which stops functioning as a con- trol register in i 2 c slave mode ( register 20-10 ). in 7-bit address masking mode, address mask bits, msk<5:1> (sspxmsk<5:1>), mask the corresponding address bits in the sspxadd register. for any msk bits that are set (msk = 1 ), the corresponding address bit is ignored (sspxadd = x ). for the module to issue an address acknowledge, it is sufficient to match only on addresses that do not have an active address mask. in 10-bit address masking mode, the msk<5:2> bits mask the corresponding address bits in the sspxadd register. in addition, msk1 simultaneously masks the two lsbs of the address (sspxadd<1:0>). for any mskx bits that are active (msk = 1 ), the corre- sponding address bit is ignored (spxadd = x ). also note that although in 10-bit address masking mode, the upper address bits re-use part of the sspxadd register bits. the address mask bits do not interact with those bits; they only affect the lower address bits. example 20-3: address masking examples in 5-bit masking mode note 1: msk1 masks the two least significant bits of the address. 2: the two most significant bits of the address are not affected by address masking. 7-bit addressing: sspxadd<7:1> = a0h ( 1010000 ) (sspxadd<0> is assumed to be ? 0 ?) msk<5:1> = 00111 addresses acknowledged: a0h, a2h, a4h, a6h, a8h, aah, ach, aeh 10-bit addressing: sspxadd<7:0> = a0h ( 10100000 ) (the two msb of the address are ignored in this example, since they are not affected by masking.) msk<5:1> = 00111 addresses acknowledged: a0h, a1h, a2h, a3h, a4h, a5h, a6h, a7h, a8h, a9h, aah, abh, ach, adh, aeh, afh
pic18f97j94 family ds30575a-page 382 ? 2012 microchip technology inc. 20.5.4.3 7-bit address masking mode unlike 5-bit masking, 7-bit address masking mode uses a mask of up to 8 bits (in 10-bit addressing) to define a range of addresses that can be acknowl- edged, using the lowest bits of the incoming address. this allows the module to acknowledge up to 127 different addresses with 7-bit addressing, or 255 with 10-bit addressing (see example 20-4 ). this mode is the default configuration of the module, which is selected when msspmsk<2:1> are unprogrammed (? 1 ?). the address mask for 7-bit address masking mode is stored in the sspxmsk register, instead of the sspxcon2 register. sspxmsk is a separate hard- ware register within the module, but it is not directly addressable. instead, it shares an address in the sfr space with the sspxadd register. to access the sspxmsk register, it is necessary to select mssp mode, ? 1001 ? (sspxcon1<3:0> = 1001 ) and then read or write to the location of sspxadd. to use 7-bit address masking mode, it is necessary to initialize sspxmsk with a value before selecting the i 2 c slave addressing mode. thus, the required sequence of events is: 1. select sspxmsk access mode (sspxcon2<3:0> = 1001 ). 2. write the mask value to the appropriate sspxadd register address (fc8h for mssp1, f6eh for mssp2). 3. set the appropriate i 2 c slave mode (sspxcon2<3:0> = 0111 for 10-bit addressing, 0110 for 7-bit addressing). setting or clearing mask bits in sspxmsk behaves in the opposite manner of the mskx bits in 5-bit address masking mode. that is, clearing a bit in sspxmsk causes the corresponding address bit to be masked; setting the bit requires a match in that position. sspxmsk resets to all ? 1 ?s upon any reset condition, and therefore, has no effect on the standard mssp operation until written with a mask value. with 7-bit addressing, sspxmsk<7:1> bits mask the corresponding address bits in the sspxadd register. for any sspxmsk bits that are active (sspxmsk = 0 ), the corresponding sspxadd address bit is ignored (sspxadd = x ). for the module to issue an address acknowledge, it is sufficient to match only on addresses that do not have an active address mask. with 10-bit addressing, sspxmsk<7:0> bits mask the corresponding address bits in the sspxadd register. for any sspxmsk bits that are active (= 0 ), the corre- sponding sspxadd address bit is ignored (sspxadd = x ). example 20-4: address masking examples in 7-bit masking mode note: the two most significant bits of the address are not affected by address masking. 7-bit addressing: sspxadd<7:1> = 1010 000 sspxmsk<7:1> = 1111 001 addresses acknowledged = ach, a8h, a4h, a0h 10-bit addressing: sspxadd<7:0> = 1010 0000 (the two msb are ignored in this example since they are not affected) sspxmsk<5:1> = 1111 0011 addresses acknowledged = ach, a8h, a4h, a0h
? 2012 microchip technology inc. ds30575a-page 383 pic18f97j94 family 20.5.5 reception when the r/w bit of the address byte is clear and an address match occurs, the r/w bit of the sspxstat register is cleared. the received address is loaded into the sspxbuf register and the sdax line is held low (ack ). when the address byte overflow condition exists, then the no acknowledge (ack ) pulse is given. an overflow condition is defined if either bit, bf (sspxstat<0>), is set or bit, sspov (sspxcon1<6>), is set. an msspx interrupt is generated for each data transfer byte. the interrupt flag bit, sspxif, must be cleared in software. the sspxstat register is used to determine the status of the byte. if sen is enabled (sspxcon2<0> = 1 ), sclx will be held low (clock stretch) following each data transfer. the clock must be released by setting bit, ckp (sspxcon1<4>). see section 20.5.7 ?clock stretching? for more details. 20.5.6 transmission when the r/w bit of the incoming address byte is set and an address match occurs, the r/w bit of the sspxstat register is set. the received address is loaded into the sspxbuf register. the ack pulse will be sent on the ninth bit and pin, sclx, is held low regardless of sen (see section 20.5.7 ?clock stretching? for more details). by stretching the clock, the master will be unable to assert another clock pulse until the slave is done preparing the transmit data. the transmit data must be loaded into the sspxbuf regis- ter which also loads the sspxsr register. then, pin, sclx, should be enabled by setting bit, ckp (sspxcon1<4>). the eight data bits are shifted out on the falling edge of the sclx input. this ensures that the sdax signal is valid during the sclx high time ( figure 20-10 ). the ack pulse from the master-receiver is latched on the rising edge of the ninth sclx input pulse. if the sdax line is high (not ack ), then the data transfer is complete. in this case, when the ack is latched by the slave, the slave logic is reset and the slave monitors for another occurrence of the start bit. if the sdax line was low (ack ), the next transmit data must be loaded into the sspxbuf register. again, pin sclx must be enabled by setting bit, ckp. an msspx interrupt is generated for each data transfer byte. the sspxif bit must be cleared in software and the sspxstat register is used to determine the status of the byte. the sspxif bit is set on the falling edge of the ninth clock pulse.
pic18f97j94 family ds30575a-page 384 ? 2012 microchip technology inc. figure 20-8: i 2 c? slave mode timing with sen = 0 (reception, 7-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) sspov (sspxcon1<6>) s 12345678912345678912345 789 p a7 a6 a5 a4 a3 a2 a1 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d1 d0 ack receiving data ack receiving data r/w = 0 ack receiving address cleared in software sspxbuf is read bus master terminates transfer sspov is set because sspxbuf is still full. ack is not sent. d2 6 ckp (sspxcon<4>) (ckp does not reset to ? 0 ? when sen = 0 )
? 2012 microchip technology inc. ds30575a-page 385 pic18f97j94 family figure 20-9: i 2 c? slave mode timing with sen = 0 and msk<5:1> = 01011 (reception, 7-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) sspov (sspxcon1<6>) s 12345678912345678912345 789 p a7 a6 a5 x a3 x x d7d6 d5d4d3d2d1 d0 d7d6d5d4d3 d1d0 ack receiving data ack receiving data r/w = 0 ack receiving address cleared in software sspxbuf is read bus master terminates transfer sspov is set because sspxbuf is still full. ack is not sent. d2 6 ckp (sspxcon<4>) (ckp does not reset to ? 0 ? when sen = 0 ) note 1: x = don?t care (i.e., address bit can either be a ? 1 ? or a ? 0 ?). 2: in this example, an address equal to a7.a6.a5.x.a3.x.x will be acknowledged and cause
pic18f97j94 family ds30575a-page 386 ? 2012 microchip technology inc. figure 20-10: i 2 c? slave mode timing (transmission, 7-bit address) sdax sclx bf (sspxstat<0>) a6 a5 a4 a3 a2 a1 d6 d5 d4 d3 d2 d1 d0 1 2 3 4 5 6 7 8 2 3 4 5 6 7 8 9 sspxbuf is written in software cleared in software data in sampled s ack transmitting data r/w = 1 ack receiving address a7 d7 9 1 d6 d5 d4 d3 d2 d1 d0 2 3 4 5 6 7 8 9 sspxbuf is written in software cleared in software from sspxif isr transmitting data d7 1 ckp (sspxcon<4>) p ack ckp is set in software ckp is set in software sclx held low while cpu responds to sspxif sspxif (pir1<3> or pir3<7>) from sspxif isr clear by reading
? 2012 microchip technology inc. ds30575a-page 387 pic18f97j94 family figure 20-11: i 2 c? slave mode timing with sen = 0 and msk<5:1> = 01001 (reception, 10-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9 a8 a7 a6 a5 x a3 a2 x x d7 d6 d5 d4 d3 d1 d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 cleared in software receive second byte of address cleared by hardware when sspxadd is updated with low byte of address ua (sspxstat<1>) clock is held low until update of sspxadd has taken place ua is set indicating that the sspxadd needs to be updated ua is set indicating that sspxadd needs to be updated cleared by hardware when sspxadd is updated with high byte of address sspxbuf is written with contents of sspxsr dummy read of sspxbuf to clear bf flag ack ckp (sspxcon<4>) 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus master terminates transfer d2 6 ack cleared in software cleared in software sspov (sspxcon1<6>) sspov is set because sspxbuf is still full. ack is not sent. (ckp does not reset to ? 0 ? when sen = 0 ) clock is held low until update of sspxadd has taken place note 1: x = don?t care (i.e., address bit can either be a ? 1 ? or a ? 0 ?). 2: in this example, an address equal to a9.a8.a7.a6.a5.x.a3.a2.x.x will be acknowledged and cause an interrupt.
pic18f97j94 family ds30575a-page 388 ? 2012 microchip technology inc. figure 20-12: i 2 c? slave mode timing with sen = 0 (reception, 10-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9a8 a7 a6a5 a4a3a2a1 a0 d7 d6d5d4d3 d1d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 cleared in software receive second byte of address cleared by hardware when sspxadd is updated with low byte of address ua (sspxstat<1>) clock is held low until update of sspxadd has taken place ua is set indicating that the sspxadd needs to be updated ua is set indicating that sspxadd needs to be updated cleared by hardware when sspxadd is updated with high byte of address sspxbuf is written with contents of sspxsr dummy read of sspxbuf to clear bf flag ack ckp (sspxcon<4>) 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus master terminates transfer d2 6 ack cleared in software cleared in software sspov (sspxcon1<6>) sspov is set because sspxbuf is still full. ack is not sent. (ckp does not reset to ? 0 ? when sen = 0 ) clock is held low until update of sspxadd has taken place
? 2012 microchip technology inc. ds30575a-page 389 pic18f97j94 family figure 20-13: i 2 c? slave mode timing (transmission, 10-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) s 1234 5 6789 1 2345 678 9 12345 7 89 p 1 1 1 1 0 a9a8 a7 a6a5a4a3a2a1 a0 1 1 1 1 0 a8 r/w = 1 ack ack r/w = 0 ack receive first byte of address cleared in software bus master terminates transfer a9 6 receive second byte of address cleared by hardware when sspxadd is updated with low byte of address ua (sspxstat<1>) clock is held low until update of sspxadd has taken place ua is set indicating that the sspxadd needs to be updated ua is set indicating that sspxadd needs to be updated cleared by hardware when sspxadd is updated with high byte of address. sspxbuf is written with contents of sspxsr dummy read of sspxbuf to clear bf flag receive first byte of address 12345 789 d7 d6 d5 d4 d3 d1 ack d2 6 transmitting data byte d0 dummy read of sspxbuf to clear bf flag sr cleared in software write of sspxbuf initiates transmit cleared in software completion of clears bf flag ckp (sspxcon1<4>) ckp is set in software ckp is automatically cleared in hardware, holding sclx low clock is held low until update of sspxadd has taken place data transmission clock is held low until ckp is set to ? 1 ? third address sequence bf flag is clear at the end of the
pic18f97j94 family ds30575a-page 390 ? 2012 microchip technology inc. 20.5.7 clock stretching both 7-bit and 10-bit slave modes implement automatic clock stretching during a transmit sequence. the sen bit (sspxcon2<0>) allows clock stretching to be enabled during receives. setting sen will cause the sclx pin to be held low at the end of each data receive sequence. 20.5.7.1 clock stretching for 7-bit slave receive mode (sen = 1 ) in 7-bit slave receive mode, on the falling edge of the ninth clock at the end of the ack sequence, if the bf bit is set, the ckp bit in the sspxcon1 register is auto- matically cleared, forcing the sclx output to be held low. the ckp bit, being cleared to ? 0 ?, will assert the sclx line low. the ckp bit must be set in the user?s isr before reception is allowed to continue. by holding the sclx line low, the user has time to service the isr and read the contents of the sspxbuf before the mas- ter device can initiate another receive sequence. this will prevent buffer overruns from occurring (see figure 20-15 ). 20.5.7.2 clock stretching for 10-bit slave receive mode (sen = 1 ) in 10-bit slave receive mode, during the address sequence, clock stretching automatically takes place but ckp is not cleared. during this time, if the ua bit is set after the ninth clock, clock stretching is initiated. the ua bit is set after receiving the upper byte of the 10-bit address, and following the receive of the second byte of the 10-bit address, with the r/w bit cleared to ? 0 ?. the release of the clock line occurs upon updating sspxadd. clock stretching will occur on each data receive sequence as described in 7-bit mode. 20.5.7.3 clock stretching for 7-bit slave transmit mode the 7-bit slave transmit mode implements clock stretching by clearing the ckp bit after the falling edge of the ninth clock if the bf bit is clear. this occurs regardless of the state of the sen bit. the user?s isr must set the ckp bit before transmis- sion is allowed to continue. by holding the sclx line low, the user has time to service the isr and load the contents of the sspxbuf before the master device can initiate another transmit sequence (see figure 20-10 ). 20.5.7.4 clock stretching for 10-bit slave transmit mode in 10-bit slave transmit mode, clock stretching is controlled during the first two address sequences by the state of the ua bit, just as it is in 10-bit slave receive mode. the first two addresses are followed by a third address sequence, which contains the high- order bits of the 10-bit address and the r/w bit set to ? 1 ?. after the third address sequence is performed, the ua bit is not set, the module is now configured in transmit mode and clock stretching is controlled by the bf flag as in 7-bit slave transmit mode (see figure 20-13 ). note 1: if the user reads the contents of the sspxbuf before the falling edge of the ninth clock, thus clearing the bf bit, the ckp bit will not be cleared and clock stretching will not occur. 2: the ckp bit can be set in software regardless of the state of the bf bit. the user should be careful to clear the bf bit in the isr before the next receive sequence in order to prevent an overflow condition. note: if the user polls the ua bit and clears it by updating the sspxadd register before the falling edge of the ninth clock occurs, and if the user hasn?t cleared the bf bit by reading the sspxbuf register before that time, then the ckp bit will still not be asserted low. clock stretching, on the basis of the state of the bf bit, only occurs during a data sequence, not an address sequence. note 1: if the user loads the contents of sspxbuf, setting the bf bit before the falling edge of the ninth clock, the ckp bit will not be cleared and clock stretching will not occur. 2: the ckp bit can be set in software, regardless of the state of the bf bit.
? 2012 microchip technology inc. ds30575a-page 391 pic18f97j94 family 20.5.7.5 clock synchronization and the ckp bit when the ckp bit is cleared, the sclx output is forced to ? 0 ?. however, clearing the ckp bit will not assert the sclx output low until the sclx output is already sampled low. therefore, the ckp bit will not assert the sclx line until an external i 2 c master device has already asserted the sclx line. the sclx output will remain low until the ckp bit is set and all other devices on the i 2 c bus have deasserted sclx. this ensures that a write to the ckp bit will not violate the minimum high time requirement for sclx (see figure 20-14 ). figure 20-14: clock synchronization timing sdax sclx dx ? 1 dx wr q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 sspxcon1 ckp master device deasserts clock master device asserts clock
pic18f97j94 family ds30575a-page 392 ? 2012 microchip technology inc. figure 20-15: i 2 c? slave mode timing with sen = 1 (reception, 7-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) sspov (sspxcon1<6>) s 1 234 56 7 8 9 1 2345 67 89 1 23 45 7 89 p a7 a6 a5 a4 a3 a2 a1 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d1 d0 ack receiving data ack receiving data r/w = 0 ack receiving address cleared in software sspxbuf is read bus master terminates transfer sspov is set because sspxbuf is still full. ack is not sent. d2 6 ckp (sspxcon<4>) ckp written to ? 1 ? in if bf is cleared prior to the falling edge of the 9th clock, ckp will not be reset to ? 0 ? and no clock stretching will occur software clock is held low until ckp is set to ? 1 ? clock is not held low because buffer full bit is clear prior to falling edge of 9th clock clock is not held low because ack = 1 bf is set after falling edge of the 9th clock, ckp is reset to ? 0 ? and clock stretching occurs
? 2012 microchip technology inc. ds30575a-page 393 pic18f97j94 family figure 20-16: i 2 c? slave mode timing with sen = 1 (reception, 10-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9a8 a7 a6a5a4a3a2a1 a0 d7d6d5d4d3 d1d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 cleared in software receive second byte of address cleared by hardware when sspxadd is updated with low byte of address after falling edge ua (sspxstat<1>) clock is held low until update of sspxadd has taken place ua is set indicating that the sspxadd needs to be updated ua is set indicating that sspxadd needs to be updated cleared by hardware when sspxadd is updated with high byte of address after falling edge sspxbuf is written with contents of sspxsr dummy read of sspxbuf to clear bf flag ack ckp (sspxcon<4>) 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus master terminates transfer d2 6 ack cleared in software cleared in software sspov (sspxcon1<6>) ckp written to ?1? note: an update of the sspxadd register before note: an update of the sspxadd register in software clock is held low until update of sspxadd has taken place of ninth clock of ninth clock sspov is set because sspxbuf is still full. ack is not sent. dummy read of sspxbuf to clear bf flag clock is held low until ckp is set to ?1? clock is not held low because ack = 1
pic18f97j94 family ds30575a-page 394 ? 2012 microchip technology inc. 20.5.8 general call address support the addressing procedure for the i 2 c bus is such that the first byte after the start condition usually determines which device will be the slave addressed by the master. the exception is the general call address which can address all devices. when this address is used, all devices should, in theory, respond with an acknowledge. the general call address is one of eight addresses reserved for specific purposes by the i 2 c protocol. it consists of all ? 0 ?s with r/w = 0 . the general call address is recognized when the general call enable bit, gcen, is enabled (sspxcon2<7> set). following a start bit detect, eight bits are shifted into the sspxsr and the address is compared against the sspxadd. it is also compared to the general call address and fixed in hardware. if the general call address matches, the sspxsr is transferred to the sspxbuf, the bf flag bit is set (eighth bit), and on the falling edge of the ninth bit (ack bit), the sspxif interrupt flag bit is set. when the interrupt is serviced, the source for the interrupt can be checked by reading the contents of the sspxbuf. the value can be used to determine if the address was device-specific or a general call address. in 10-bit addressing mode, the sspxadd is required to be updated for the second half of the address to match and the ua bit is set (sspxstat<1>). if the general call address is sampled when the gcen bit is set, while the slave is configured in 10-bit addressing mode, then the second half of the address is not necessary, the ua bit will not be set and the slave will begin receiving data after the acknowledge ( figure 20-17 ). figure 20-17: slave mode general call address sequence (7 or 10-bit addressing mode) sdax sclx s sspxif bf (sspxstat<0>) sspov (sspxcon1<6>) cleared in software sspxbuf is read r/w = 0 ack general call address address is compared to general call address gcen (sspxcon2<7>) receiving data ack 123456789123456789 d7 d6 d5 d4 d3 d2 d1 d0 after ack , set interrupt ? 0 ? ? 1 ?
? 2012 microchip technology inc. ds30575a-page 395 pic18f97j94 family 20.5.9 master mode master mode is enabled by setting and clearing the appropriate sspmx bits in sspxcon1, and by setting the sspen bit. in master mode, the sclx and sdax lines are manipulated by the msspx hardware if the tris bits are set. the master mode of operation is supported by interrupt generation on the detection of the start and stop conditions. the stop (p) and start (s) bits are cleared from a reset or when the msspx module is disabled. control of the i 2 c bus may be taken when the p bit is set, or the bus is idle, with both the s and p bits clear. in firmware controlled master mode, user code conducts all i 2 c bus operations based on start and stop bit conditions. once master mode is enabled, the user has six options. 1. assert a start condition on sdax and sclx. 2. assert a repeated start condition on sdax and sclx. 3. write to the sspxbuf register initiating transmission of data/address. 4. configure the i 2 c port to receive data. 5. generate an acknowledge condition at the end of a received byte of data. 6. generate a stop condition on sdax and sclx. the following events will cause the msspx interrupt flag bit, sspxif, to be set (and msspx interrupt if enabled): ? start condition ? stop condition ? data transfer byte transmitted/received ? acknowledge transmitted ? repeated start figure 20-18: msspx block diagram (i 2 c? master mode) note: the msspx module, when configured in i 2 c master mode, does not allow queueing of events. for instance, the user is not allowed to initiate a start condition and immediately write the sspxbuf register to initiate transmission before the start condition is complete. in this case, the sspxbuf will not be written to and the wcol bit will be set, indicating that a write to the sspxbuf did not occur. read write sspxsr start bit, stop bit, sspxbuf internal data bus set/reset s, p (sspxstat), wcol (sspxcon1); shift clock msb lsb sdax acknowledge generate stop bit detect write collision detect clock arbitration state counter for end of xmit/rcv sclx sclx in bus collision sdax in receive enable clock cntl clock arbitrate/wcol detect (hold off clock source) sspxadd<6:0> baud set sspxif, bclxif; reset ackstat, pen (sspxcon2) rate generator sspm<3:0> start bit detect
pic18f97j94 family ds30575a-page 396 ? 2012 microchip technology inc. 20.5.9.1 i 2 c? master mode operation the master device generates all of the serial clock pulses and the start and stop conditions. a transfer is ended with a stop condition or with a repeated start condition. since the repeated start condition is also the beginning of the next serial transfer, the i 2 c bus will not be released. in master transmitter mode, serial data is output through sdax while sclx outputs the serial clock. the first byte transmitted contains the slave address of the receiving device (7 bits) and the read/write (r/w ) bit. in this case, the r/w bit will be logic ? 0 ?. serial data is transmitted, 8 bits at a time. after each byte is transmit- ted, an acknowledge bit is received. start and stop conditions are output to indicate the beginning and the end of a serial transfer. in master receive mode, the first byte transmitted contains the slave address of the transmitting device (7 bits) and the r/w bit. in this case, the r/w bit will be logic ? 1 ?. thus, the first byte transmitted is a 7-bit slave address, followed by a ? 1 ? to indicate the receive bit. serial data is received via sdax, while sclx outputs the serial clock. serial data is received, 8 bits at a time. after each byte is received, an acknowledge bit is transmitted. start and stop conditions indicate the beginning and end of transmission. the baud rate generator, used for the spi mode operation, is used to set the sclx clock frequency for either 100 khz, 400 khz or 1 mhz i 2 c operation. see section 20.5.10 ?baud rate? for more details. a typical transmit sequence would go as follows: 1. the user generates a start condition by setting the start enable bit, sen (sspxcon2<0>). 2. sspxif is set. the msspx module will wait the required start time before any other operation takes place. 3. the user loads the sspxbuf with the slave address to transmit. 4. address is shifted out the sdax pin until all 8 bits are transmitted. 5. the msspx module shifts in the ack bit from the slave device and writes its value into the sspxcon2 register (sspxcon2<6>). 6. the msspx module generates an interrupt at the end of the ninth clock cycle by setting the sspxif bit. 7. the user loads the sspxbuf with eight bits of data. 8. data is shifted out the sdax pin until all 8 bits are transmitted. 9. the msspx module shifts in the ack bit from the slave device and writes its value into the sspxcon2 register (sspxcon2<6>). 10. the msspx module generates an interrupt at the end of the ninth clock cycle by setting the sspxif bit. 11. the user generates a stop condition by setting the stop enable bit, pen (sspxcon2<2>). 12. interrupt is generated once the stop condition is complete.
? 2012 microchip technology inc. ds30575a-page 397 pic18f97j94 family 20.5.10 baud rate in i 2 c master mode, the baud rate generator (brg) reload value is placed in the lower 7 bits of the sspxadd register ( figure 20-19 ). when a write occurs to sspxbuf, the baud rate generator will automatically begin counting. the brg counts down to 0 and stops until another reload has taken place. the brg count is decremented, twice per instruction cycle (t cy ), on the q2 and q4 clocks. in i 2 c master mode, the brg is reloaded automatically. once the given operation is complete (i.e., transmis- sion of the last data bit is followed by ack ), the internal clock will automatically stop counting and the sclx pin will remain in its last state. table 20-2 demonstrates clock rates based on instruction cycles and the brg value loaded into sspxadd. the sspxadd brg value of ? 0x00 ? is not supported. 20.5.10.1 baud rate and module interdependence because mssp1 and mssp2 are independent, they can operate simultaneously in i 2 c master mode at different baud rates. this is done by using different brg reload values for each module. because this mode derives its basic clock source from the system clock, any changes to the clock will affect both modules in the same proportion. it may be possible to change one or both baud rates back to a previous value by changing the brg reload value. figure 20-19: baud rate generator block diagram table 20-2: i 2 c? clock rate w/brg sspm<3:0> brg down counter clko f osc /4 sspxadd<6:0> sspm<3:0> sclx reload control reload f osc f cy f cy * 2 brg value f scl (2 rollovers of brg) 64 mhz 16 mhz 32 mhz 27h 400 khz ( 1 ) 64 mhz 16 mhz 32 mhz 32h 313.72 khz 64 mhz 16 mhz 32 mhz 9fh 100 khz 16 mhz 4 mhz 8 mhz 09h 400 khz ( 1 ) 16 mhz 4 mhz 8 mhz 0ch 308 khz 16 mhz 4 mhz 8 mhz 27h 100 khz 4 mhz 1 mhz 2 mhz 02h 333 khz ( 1 ) 4 mhz 1 mhz 2 mhz 09h 100 khz 16 mhz 4 mhz 8 mhz 03h 1 mhz ( 1 , 2 ) note 1: the i 2 c interface does not conform to the 400 khz i 2 c specification (which applies to rates greater than 100 khz) in all details, but may be used with care where higher rates are required by the application. 2: a minimum of 16 mhz f osc is required to get 1 mhz i 2 c.
pic18f97j94 family ds30575a-page 398 ? 2012 microchip technology inc. 20.5.10.2 clock arbitration clock arbitration occurs when the master, during any receive, transmit or repeated start/stop condition, deasserts the sclx pin (sclx allowed to float high). when the sclx pin is allowed to float high, the baud rate generator (brg) is suspended from counting until the sclx pin is actually sampled high. when the sclx pin is sampled high, the baud rate generator is reloaded with the contents of sspxadd<6:0> and begins counting. this ensures that the sclx high time will always be at least one brg rollover count in the event that the clock is held low by an external device ( figure 20-20 ). figure 20-20: baud rate generator timing with clock arbitration sdax sclx sclx deasserted but slave holds dx ? 1 dx brg sclx is sampled high, reload takes place and brg starts its count 03h 02h 01h 00h (hold off) 03h 02h reload brg value sclx low (clock arbitration) sclx allowed to transition high brg decrements on q2 and q4 cycles
? 2012 microchip technology inc. ds30575a-page 399 pic18f97j94 family 20.5.11 i 2 c? master mode start condition timing to initiate a start condition, the user sets the start enable bit, sen (sspxcon2<0>). if the sdax and sclx pins are sampled high, the baud rate generator is reloaded with the contents of sspxadd<6:0> and starts its count. if sclx and sdax are both sampled high when the baud rate generator times out (t brg ), the sdax pin is driven low. the action of the sdax being driven low while sclx is high is the start condi- tion and causes the s bit (sspxstat<3>) to be set. following this, the baud rate generator is reloaded with the contents of sspxadd<6:0> and resumes its count. when the baud rate generator times out (t brg ), the sen bit (sspxcon2<0>) will be automatically cleared by hardware. the baud rate generator is suspended, leaving the sdax line held low and the start condition is complete. 20.5.11.1 wcol status flag if the user writes the sspxbuf when a start sequence is in progress, the wcol bit is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 20-21: first start bit timing note: if, at the beginning of the start condition, the sdax and sclx pins are already sampled low, or if during the start condi- tion, the sclx line is sampled low before the sdax line is driven low, a bus collision occurs, the bus collision interrupt flag, bclxif, is set, the start condition is aborted and the i 2 c module is reset into its idle state. note: because queueing of events is not allowed, writing to the lower 5 bits of sspxcon2 is disabled until the start condition is complete. sdax sclx s t brg 1st bit 2nd bit t brg sdax = 1 , at completion of start bit, sclx = 1 write to sspxbuf occurs here t brg hardware clears sen bit t brg write to sen bit occurs here set s bit (sspxstat<3>) and sets sspxif bit
pic18f97j94 family ds30575a-page 400 ? 2012 microchip technology inc. 20.5.12 i 2 c? master mode repeated start condition timing a repeated start condition occurs when the rsen bit (sspxcon2<1>) is programmed high and the i 2 c logic module is in the idle state. when the rsen bit is set, the sclx pin is asserted low. when the sclx pin is sampled low, the baud rate generator is loaded with the contents of sspxadd<5:0> and begins counting. the sdax pin is released (brought high) for one baud rate generator count (t brg ). when the baud rate generator times out, and if sdax is sampled high, the sclx pin will be deasserted (brought high). when sclx is sampled high, the baud rate generator is reloaded with the contents of sspxadd<6:0> and begins counting. sdax and sclx must be sampled high for one t brg . this action is then followed by assertion of the sdax pin (sdax = 0 ) for one t brg while sclx is high. following this, the rsen bit (sspxcon2<1>) will be automatically cleared and the baud rate generator will not be reloaded, leaving the sdax pin held low. as soon as a start condition is detected on the sdax and sclx pins, the s bit (sspxstat<3>) will be set. the sspxif bit will not be set until the baud rate generator has timed out. immediately following the sspxif bit getting set, the user may write the sspxbuf with the 7-bit address in 7-bit mode or the default first address in 10-bit mode. after the first eight bits are transmitted and an ack is received, the user may then transmit an additional eight bits of address (10-bit mode) or eight bits of data (7-bit mode). 20.5.12.1 wcol status flag if the user writes the sspxbuf when a repeated start sequence is in progress, the wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 20-22: repeated start condition waveform note 1: if rsen is programmed while any other event is in progress, it will not take effect. 2: a bus collision during the repeated start condition occurs if: ? sdax is sampled low when sclx goes from low-to-high. ? sclx goes low before sdax is asserted low. this may indicate that another master is attempting to transmit a data ? 1 ?. note: because queueing of events is not allowed, writing of the lower 5 bits of sspxcon2 is disabled until the repeated start condition is complete. sdax sclx sr = repeated start write to sspxcon2 occurs here: write to sspxbuf occurs here on falling edge of ninth clock, end of xmit at completion of start bit, hardware clears rsen bit 1st bit s bit set by hardware t brg sdax = 1 , sdax = 1 , sclx (no change). sclx = 1 and sets sspxif rsen bit set by hardware t brg t brg t brg t brg
? 2012 microchip technology inc. ds30575a-page 401 pic18f97j94 family 20.5.13 i 2 c? master mode transmission transmission of a data byte, a 7-bit address or the other half of a 10-bit address, is accomplished by simply writing a value to the sspxbuf register. this action will set the buffer full flag bit, bf, and allow the baud rate generator to begin counting and start the next transmission. each bit of address/data will be shifted out onto the sdax pin after the falling edge of sclx is asserted (see data hold time specification parameter 106 ). sclx is held low for one baud rate generator rollover count (t brg ). data should be valid before sclx is released high (see data setup time specification parameter 107 ). when the sclx pin is released high, it is held that way for t brg . the data on the sdax pin must remain stable for that duration and some hold time after the next falling edge of sclx. after the eighth bit is shifted out (the falling edge of the eighth clock), the bf flag is cleared and the master releases sdax. this allows the slave device being addressed to respond with an ack bit during the ninth bit time if an address match occurred, or if data was received properly. the status of ack is written into the ackdt bit on the falling edge of the ninth clock. if the master receives an acknowledge, the acknowledge status bit, ackstat, is cleared; if not, the bit is set. after the ninth clock, the sspxif bit is set and the master clock (baud rate generator) is suspended until the next data byte is loaded into the sspxbuf, leaving sclx low and sdax unchanged ( figure 20-23 ). after the write to the sspxbuf, each bit of the address will be shifted out on the falling edge of sclx until all seven address bits and the r/w bit are completed. on the falling edge of the eighth clock, the master will deassert the sdax pin, allowing the slave to respond with an acknowledge. on the falling edge of the ninth clock, the master will sample the sdax pin to see if the address was recognized by a slave. the status of the ack bit is loaded into the ackstat status bit (sspxcon2<6>). following the falling edge of the ninth clock transmission of the address, the sspxif flag is set, the bf flag is cleared and the baud rate generator is turned off until another write to the sspxbuf takes place, holding sclx low and allowing sdax to float. 20.5.13.1 bf status flag in transmit mode, the bf bit (sspxstat<0>) is set when the cpu writes to sspxbuf and is cleared when all 8 bits are shifted out. 20.5.13.2 wcol status flag if the user writes the sspxbuf when a transmit is already in progress (i.e., sspxsr is still shifting out a data byte), the wcol bit is set and the contents of the buffer are unchanged (the write doesn?t occur) after 2t cy after the sspxbuf write. if sspxbuf is rewritten within 2 t cy , the wcol bit is set and sspxbuf is updated. this may result in a corrupted transfer. the user should verify that the wcol bit is clear after each write to sspxbuf to ensure the transfer is correct. in all cases, wcol must be cleared in software. 20.5.13.3 ackstat status flag in transmit mode, the ackstat bit (sspxcon2<6>) is cleared when the slave has sent an acknowledge (ack = 0 ) and is set when the slave does not acknowl- edge (ack = 1 ). a slave sends an acknowledge when it has recognized its address (including a general call), or when the slave has properly received its data. 20.5.14 i 2 c? master mode reception master mode reception is enabled by programming the receive enable bit, rcen (sspxcon2<3>). the baud rate generator begins counting, and on each rollover, the state of the sclx pin changes (high- to-low/low-to-high) and data is shifted into the sspxsr. after the falling edge of the eighth clock, the receive enable flag is automatically cleared, the con- tents of the sspxsr are loaded into the sspxbuf, the bf flag bit is set, the sspxif flag bit is set and the baud rate generator is suspended from counting, holding sclx low. the msspx is now in idle state awaiting the next command. when the buffer is read by the cpu, the bf flag bit is automatically cleared. the user can then send an acknowledge bit at the end of reception by setting the acknowledge sequence enable bit, acken (sspxcon2<4>). 20.5.14.1 bf status flag in receive operation, the bf bit is set when an address or data byte is loaded into sspxbuf from sspxsr. it is cleared when the sspxbuf register is read. 20.5.14.2 sspov status flag in receive operation, the sspov bit is set when 8 bits are received into the sspxsr and the bf flag bit is already set from a previous reception. 20.5.14.3 wcol status flag if the user writes the sspxbuf when a receive is already in progress (i.e., sspxsr is still shifting in a data byte), the wcol bit is set and the contents of the buffer are unchanged (the write doesn?t occur). note: the msspx module must be in an inactive state before the rcen bit is set or the rcen bit will be disregarded.
pic18f97j94 family ds30575a-page 402 ? 2012 microchip technology inc. figure 20-23: i 2 c? master mode waveform (transmission, 7 or 10-bit address) sdax sclx sspxif bf (sspxstat<0>) sen a7 a6 a5 a4 a3 a2 a1 ack = 0 d7 d6 d5 d4 d3 d2 d1 d0 ack transmitting data or second half r/w = 0 transmit address to slave 123456789 123456789 p cleared in software service routine sspxbuf is written in software from msspx interrupt after start condition, sen cleared by hardware s sspxbuf written with 7-bit address and r/w , start transmit sclx held low while cpu responds to sspxif sen = 0 of 10-bit address write sspxcon2<0> (sen = 1 ), start condition begins from slave, clear ackstat bit (sspxcon2<6>) ackstat in sspxcon2 = 1 cleared in software sspxbuf written pen r/w cleared in software
? 2012 microchip technology inc. ds30575a-page 403 pic18f97j94 family figure 20-24: i 2 c? master mode waveform (reception, 7-bit address) p 9 8 7 6 5 d0 d1 d2 d3 d4 d5 d6 d7 s a7 a6 a5 a4 a3 a2 a1 sdax sclx 12 3 4 5 6 7 8 9 12 3 4 5 678 9 1234 bus master terminates transfer ack receiving data from slave receiving data from slave d0 d1 d2 d3 d4 d5 d6 d7 ack r/w = 1 transmit address to slave sspxif bf ack is not sent write to sspxcon2<0> (sen = 1 ), write to sspxbuf occurs here, ack from slave master configured as a receiver by programming sspxcon2<3> (rcen = 1 ) pen bit = 1 written here data shifted in on falling edge of clk cleared in software start xmit sen = 0 sspov sdax = 0 , sclx = 1 , while cpu (sspxstat<0>) ack cleared in software cleared in software set sspxif interrupt at end of receive set p bit (sspxstat<4>) and sspxif ack from master, set sspxif at end set sspxif interrupt at end of acknowledge sequence set sspxif interrupt at end of acknowledge sequence of receive set acken, start acknowledge sequence, sdax = ackdt = 1 rcen cleared automatically rcen = 1 , start next receive write to sspxcon2<4> to start acknowledge sequence, sdax = ackdt (sspxcon2<5>) = 0 rcen cleared automatically responds to sspxif acken begin start condition cleared in software sdax = ackdt = 0 last bit is shifted into sspxsr and contents are unloaded into sspxbuf cleared in software sspov is set because sspxbuf is still full
pic18f97j94 family ds30575a-page 404 ? 2012 microchip technology inc. 20.5.15 acknowledge sequence timing an acknowledge sequence is enabled by setting the acknowledge sequence enable bit, acken (sspxcon2<4>). when this bit is set, the sclx pin is pulled low and the contents of the acknowledge data bit are presented on the sdax pin. if the user wishes to gen- erate an acknowledge, then the ackdt bit should be cleared. if not, the user should set the ackdt bit before starting an acknowledge sequence. the baud rate gen- erator then counts for one rollover period (t brg ) and the sclx pin is deasserted (pulled high). when the sclx pin is sampled high (clock arbitration), the baud rate gener- ator counts for t brg ; the sclx pin is then pulled low. following this, the acken bit is automatically cleared, the baud rate generator is turned off and the msspx module then goes into an inactive state ( figure 20-25 ). 20.5.15.1 wcol status flag if the user writes the sspxbuf when an acknowledge sequence is in progress, then wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). 20.5.16 stop condition timing a stop bit is asserted on the sdax pin at the end of a receive/transmit by setting the stop sequence enable bit, pen (sspxcon2<2>). at the end of a receive/ transmit, the sclx line is held low after the falling edge of the ninth clock. when the pen bit is set, the master will assert the sdax line low. when the sdax line is sampled low, the baud rate generator is reloaded and counts down to 0 . when the baud rate generator times out, the sclx pin will be brought high and one t brg (baud rate generator rollover count) later, the sdax pin will be deasserted. when the sdax pin is sampled high while sclx is high, the p bit (sspxstat<4>) is set. a t brg later, the pen bit is cleared and the sspxif bit is set ( figure 20-26 ). 20.5.16.1 wcol status flag if the user writes the sspxbuf when a stop sequence is in progress, then the wcol bit is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 20-25: acknowledge sequence waveform figure 20-26: stop condition receive or transmit mode note: t brg = one baud rate generator period. sdax sclx sspxif set at acknowledge sequence starts here, write to sspxcon2, acken automatically cleared cleared in t brg t brg the end of receive 8 acken = 1 , ackdt = 0 d0 9 sspxif software sspxif set at the end of acknowledge sequence cleared in software ack sclx sdax sdax is asserted low before rising edge of clock write to sspxcon2, set pen falling edge of sclx = 1 for t brg , followed by sdax = 1 for t brg 9th clock sclx brought high after t brg note: t brg = one baud rate generator period. t brg t brg after sdax is sampled high; p bit (sspxstat<4>) is set t brg to set up stop condition ack p t brg pen bit (sspxcon2<2>) is cleared by hardware and the sspxif bit is set
? 2012 microchip technology inc. ds30575a-page 405 pic18f97j94 family 20.5.17 sleep operation while in sleep mode, the i 2 c module can receive addresses or data and when an address match or complete byte transfer occurs, wake the processor from sleep (if the msspx interrupt is enabled). 20.5.18 effects of a reset a reset disables the msspx module and terminates the current transfer. 20.5.19 multi-master mode in multi-master mode, the interrupt generation on the detection of the start and stop conditions allows the determination of when the bus is free. the stop (p) and start (s) bits are cleared from a reset or when the msspx module is disabled. control of the i 2 c bus may be taken when the p bit (sspxstat<4>) is set, or the bus is idle, with both the s and p bits clear. when the bus is busy, enabling the msspx interrupt will generate the interrupt when the stop condition occurs. in multi-master operation, the sdax line must be mon- itored for arbitration to see if the signal level is the expected output level. this check is performed in hardware with the result placed in the bclxif bit. the states where arbitration can be lost are: ? address transfer ? data transfer ? a start condition ? a repeated start condition ? an acknowledge condition 20.5.20 multi -master communication, bus collision and bus arbitration multi-master mode support is achieved by bus arbitra- tion. when the master outputs address/data bits onto the sdax pin, arbitration takes place when the master outputs a ? 1 ? on sdax, by letting sdax float high, and another master asserts a ? 0 ?. when the sclx pin floats high, data should be stable. if the expected data on sdax is a ? 1 ? and the data sampled on the sdax pin = 0 , then a bus collision has taken place. the master will set the bus collision interrupt flag, bclxif, and reset the i 2 c port to its idle state ( figure 20-27 ). if a transmit was in progress when the bus collision occurred, the transmission is halted, the bf flag is cleared, the sdax and sclx lines are deasserted and the sspxbuf can be written to. when the user services the bus collision interrupt service routine and if the i 2 c bus is free, the user can resume communication by asserting a start condition. if a start, repeated start, stop or acknowledge condi- tion was in progress when the bus collision occurred, the condition is aborted, the sdax and sclx lines are deasserted and the respective control bits in the sspxcon2 register are cleared. when the user services the bus collision interrupt service routine (isr), and if the i 2 c bus is free, the user can resume communication by asserting a start condition. the master will continue to monitor the sdax and sclx pins. if a stop condition occurs, the sspxif bit will be set. a write to the sspxbuf will start the transmission of data at the first data bit regardless of where the transmitter left off when the bus collision occurred. in multi-master mode, the interrupt generation on the detection of start and stop conditions allows the determi- nation of when the bus is free. control of the i 2 c bus can be taken when the p bit is set in the sspxstat register, or the bus is idle and the s and p bits are cleared. figure 20-27: bus collision timing for transmit and acknowledge sdax sclx bclxif sdax released sdax line pulled low by another source sample sdax. while sclx is high, data doesn?t match what is driven bus collision has occurred set bus collision interrupt (bclxif) by the master; by master data changes while sclx = 0
pic18f97j94 family ds30575a-page 406 ? 2012 microchip technology inc. 20.5.20.1 bus collision during a start condition during a start condition, a bus collision occurs if: a) sdax or sclx is sampled low at the beginning of the start condition ( figure 20-28 ). b) sclx is sampled low before sdax is asserted low ( figure 20-29 ). during a start condition, both the sdax and the sclx pins are monitored. if the sdax pin is already low, or the sclx pin is already low, then all of the following occur: ? the start condition is aborted, ? the bclxif flag is set and ? the msspx module is reset to its inactive state ( figure 20-28 ) the start condition begins with the sdax and sclx pins deasserted. when the sdax pin is sampled high, the baud rate generator is loaded from sspxadd<6:0> and counts down to 0. if the sclx pin is sampled low while sdax is high, a bus collision occurs because it is assumed that another master is attempting to drive a data ? 1 ? during the start condition. if the sdax pin is sampled low during this count, the brg is reset and the sdax line is asserted early ( figure 20-30 ). if, however, a ? 1 ? is sampled on the sdax pin, the sdax pin is asserted low at the end of the brg count. the baud rate generator is then reloaded and counts down to 0. if the sclx pin is sampled as ? 0 ? during this time, a bus collision does not occur. at the end of the brg count, the sclx pin is asserted low. figure 20-28: bus collision during start condition (sdax only) note: the reason that bus collision is not a fac- tor during a start condition is that no two bus masters can assert a start condition at the exact same time. therefore, one master will always assert sdax before the other. this condition does not cause a bus collision because the two masters must be allowed to arbitrate the first address following the start condition. if the address is the same, arbitration must be allowed to continue into the data portion, repeated start or stop conditions. sdax sclx sen sdax sampled low before sdax goes low before the sen bit is set. s bit and sspxif set because msspx module reset into idle state sen cleared automatically because of bus collision, s bit and sspxif set because set sen, enable start condition if sdax = 1 , sclx = 1 sdax = 0 , sclx = 1 bclxif s sspxif sdax = 0 , sclx = 1 sspxif and bclxif are cleared in software sspxif and bclxif are cleared in software set bclxif, start condition, set bclxif,
? 2012 microchip technology inc. ds30575a-page 407 pic18f97j94 family figure 20-29: bus collision during start condition (sclx = 0 ) figure 20-30: brg reset due to sdax arbitration during start condition sdax sclx sen bus collision occurs, set bclxif sclx = 0 before sdax = 0 , set sen, enable start sequence if sdax = 1 , sclx = 1 t brg t brg sdax = 0 , sclx = 1 bclxif s sspxif interrupt cleared in software bus collision occurs, set bclxif sclx = 0 before brg time-out, ? 0 ?? 0 ? ? 0 ? ? 0 ? sdax sclx sen set s less than t brg t brg sdax = 0 , sclx = 1 bclxif s sspxif s interrupts cleared in software set sspxif sdax = 0 , sclx = 1 , sclx pulled low after brg time-out set sspxif ? 0 ? sdax pulled low by other master, reset brg and assert sdax set sen, enable start sequence if sdax = 1 , sclx = 1
pic18f97j94 family ds30575a-page 408 ? 2012 microchip technology inc. 20.5.20.2 bus collision during a repeated start condition during a repeated start condition, a bus collision occurs if: a) a low level is sampled on sdax when sclx goes from a low level to a high level. b) sclx goes low before sdax is asserted low, indicating that another master is attempting to transmit a data ? 1 ?. when the user deasserts sdax and the pin is allowed to float high, the brg is loaded with sspxadd<6:0> and counts down to 0 . the sclx pin is then deasserted and when sampled high, the sdax pin is sampled. if sdax is low, a bus collision has occurred (i.e., another master is attempting to transmit a data ? 0 ?, figure 20-31 ). if sdax is sampled high, the brg is reloaded and begins counting. if sdax goes from high-to-low before the brg times out, no bus collision occurs because no two masters can assert sdax at exactly the same time. if sclx goes from high-to-low before the brg times out and sdax has not already been asserted, a bus collision occurs. in this case, another master is attempting to transmit a data ? 1 ? during the repeated start condition (see figure 20-32 ). if, at the end of the brg time-out, both sclx and sdax are still high, the sdax pin is driven low and the brg is reloaded and begins counting. at the end of the count, regardless of the status of the sclx pin, the sclx pin is driven low and the repeated start condition is complete. figure 20-31: bus collision during a repeated start condition (case 1) figure 20-32: bus collision during repeated start condition (case 2) sdax sclx rsen bclxif s sspxif sample sdax when sclx goes high, if sdax = 0 , set bclxif and release sdax and sclx cleared in software ?0? ?0? sdax sclx bclxif rsen s sspxif interrupt cleared in software sclx goes low before sdax, set bclxif, release sdax and sclx t brg t brg ?0?
? 2012 microchip technology inc. ds30575a-page 409 pic18f97j94 family 20.5.20.3 bus collision during a stop condition bus collision occurs during a stop condition if: a) after the sdax pin has been deasserted and allowed to float high, sdax is sampled low after the brg has timed out. b) after the sclx pin is deasserted, sclx is sampled low before sdax goes high. the stop condition begins with sdax asserted low. when sdax is sampled low, the sclx pin is allowed to float. when the pin is sampled high (clock arbitration), the baud rate generator is loaded with sspxadd<6:0> and counts down to 0. after the brg times out, sdax is sampled. if sdax is sampled low, a bus collision has occurred. this is due to another mas- ter attempting to drive a data ? 0 ? ( figure 20-33 ). if the sclx pin is sampled low before sdax is allowed to float high, a bus collision occurs. this is another case of another master attempting to drive a data ? 0 ? ( figure 20-34 ). figure 20-33: bus collision during a stop condition (case 1) figure 20-34: bus collision during a stop condition (case 2) sdax sclx bclxif pen p sspxif t brg t brg t brg sdax asserted low sdax sampled low after t brg , set bclxif ?0? ?0? sdax sclx bclxif pen p sspxif t brg t brg t brg assert sdax sclx goes low before sdax goes high, set bclxif ?0? ?0?
pic18f97j94 family ds30575a-page 410 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 411 pic18f97j94 family 21.0 enhanced universal synchronous asynchronous receiver transmitter (eusart) the enhanced universal synchronous asynchronous receiver transmitter (eusart) module is one of four serial i/o modules. (generically, the eusart is also known as a serial communications interface or sci.) the eusart can be configured as a full-duplex, asynchronous system that can communicate with peripheral devices, such as crt terminals and personal computers. it can also be configured as a half-duplex synchronous system that can communicate with peripheral devices, such as a/d or d/a integrated circuits, serial eeproms, etc. the enhanced usart module implements additional features, including automatic baud rate detection and calibration, automatic wake-up on sync break recep- tion and 12-bit break character transmit. these make it ideally suited for use in local interconnect network bus (lin/j2602 bus) systems. all members of the pic18f97j94 family are equipped with four independent eusart modules, referred to as eusart1, eusart2, eusart3 and eusart4. they can be configured in the following modes: ? asynchronous (full duplex) with: - auto-wake-up on character reception - auto-baud calibration - 12-bit break character transmission ? synchronous ? master (half duplex) with selectable clock polarity ? synchronous ? slave (half duplex) with selectable clock polarity the enhanced usart module has the following enhancements over the ausart module: ? selectable 16-bit baud rate generator mode ? interrupt on sync break character received; allows an asynchronous wake-up from sleep ? 12-bit break character transmit ? auto-baud calibration on sync character ? clock polarity select for synchronous mode ? transmit and receive polarity select for asynchronous mode ? receive shift register empty status bit ? local interconnect network (lin/j2602) protocol standard the enhanced usart module has the following irda ? related enhancements over previous enhanced usart modules: ? 16x baud clock output for irda support ? irda encoder and decoder logic the pins of eusart1 through eusart4 are multi- plexed with functions using pps-lite. the txx and rxx pins of each eusart can be individually controlled using pps-lite registers, respectively. refer to section 11.15 ?pps-lite? for setting up eusart1 through eusart4. the operation of each enhanced usart module is controlled through seven registers: ? rcstax ? eusartx receive status and control register ? txstax ? eusartx transmit status and control register ? baudconx ? baud rate control register ? spbrgx ? baud rate generator register ? spbrghx ? baud rate generator high register ? rcregx ? eusartx receive data register ? txregx ? eusartx transmit data register these are detailed on the following pages in register 21-1 , register 21-2 and register 21-3 , respectively. note: the eusart control will automatically reconfigure the pin from input to output as needed. note: throughout this section, references to register and bit names that may be asso- ciated with a specific eusart module are referred to generically by the use of ?x? in place of the specific module number. thus, ?rcstax? might refer to the receive status register for either eusart1, eusart2, eusart3 or eusart4.
pic18f97j94 family ds30575a-page 412 ? 2012 microchip technology inc. register 21-1: txstax: eusartx trans mit status and control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-1 r/w-0 csrc tx9 txen ( 1 ) sync sendb brgh trmt tx9d bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 csrc: clock source select bit asynchronous mode: don?t care. synchronous mode: 1 = master mode (clock generated internally from brg) 0 = slave mode (clock from external source) bit 6 tx9: 9-bit transmit enable bit 1 = selects 9-bit transmission 0 = selects 8-bit transmission bit 5 txen: transmit enable bit ( 1 ) 1 = transmit is enabled 0 = transmit is disabled bit 4 sync: eusartx mode select bit 1 = synchronous mode 0 = asynchronous mode bit 3 sendb: send break character bit asynchronous mode: 1 = send sync break on next transmission (cleared by hardware upon completion) 0 = sync break transmission has completed synchronous mode: don?t care. bit 2 brgh: high baud rate select bit asynchronous mode: 1 = high speed 0 = low speed synchronous mode: unused in this mode. bit 1 trmt: transmit shift register status bit 1 = tsr is empty 0 = tsr is full bit 0 tx9d: 9th bit of transmit data can be address/data bit or a parity bit. note 1: sren/cren overrides txen in sync mode.
? 2012 microchip technology inc. ds30575a-page 413 pic18f97j94 family register 21-2: rcstax: eusartx receive status and control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r-0 r-x spen rx9 sren cren adden ferr oerr rx9d bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 spen: serial port enable bit 1 = serial port is enabled 0 = serial port is disabled (held in reset) bit 6 rx9: 9-bit receive enable bit 1 = selects 9-bit reception 0 = selects 8-bit reception bit 5 sren: single receive enable bit asynchronous mode : don?t care. synchronous mode ? master: 1 = enables single receive 0 = disables single receive this bit is cleared after reception is complete. synchronous mode ? slave: don?t care. bit 4 cren: continuous receive enable bit asynchronous mode: 1 = enables receiver 0 = disables receiver synchronous mode: 1 = enables continuous receive until enable bit, cren, is cleared (cren overrides sren) 0 = disables continuous receive bit 3 adden: address detect enable bit asynchronous mode 9-bit (rx9 = 1 ): 1 = enables address detection, enables interrupt and loads the receive buffer when rsr<8> is set 0 = disables address detection, all bytes are received and the ninth bit can be used as a parity bit asynchronous mode 9-bit (rx9 = 0 ): don?t care. bit 2 ferr: framing error bit 1 = framing error (can be cleared by reading the rcregx register and receiving the next valid byte) 0 = no framing error bit 1 oerr: overrun error bit 1 = overrun error (can be cleared by clearing bit, cren) 0 = no overrun error bit 0 rx9d: 9th bit of received data this can be an address/data bit or a parity bit and must be calculated by user firmware.
pic18f97j94 family ds30575a-page 414 ? 2012 microchip technology inc. register 21-3: baudconx: baud ra te control register x r/w-0 r-1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 abdovf rcidl rxdtp txckp brg16 iren wue abden bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 abdovf: auto-baud acquisition rollover status bit 1 = a brg rollover has occurred during auto-baud rate detect mode (must be cleared in software) 0 = no brg rollover has occurred bit 6 rcidl: receive operation idle status bit 1 = receive operation is idle 0 = receive operation is active bit 5 rxdtp: data/receive polarity select bit asynchronous mode: 1 = receive data (rxx) is inverted (active-low) 0 = receive data (rxx) is not inverted (active-high) asynchronous irda mode: no effect on operation synchronous mode: 1 = data (dtx) is inverted (active-low) 0 = data (dtx) is not inverted (active-high) bit 4 txckp: synchronous clock polarity select bit asynchronous mode: 1 = idle state for transmit (txx) is a low level 0 = idle state for transmit (txx) is a high level asynchronous irda mode: 1 = idle state for irda transmit (tx) is a high level (? 1 ?) 0 = idle state for irda transmit (tx) is a low level (? 0 ?) synchronous mode: 1 = idle state for clock (ckx) is a high level 0 = idle state for clock (ckx) is a low level bit 3 brg16: 16-bit baud rate register enable bit 1 = 16-bit baud rate generator ? spbrghx and spbrgx 0 = 8-bit baud rate generator ? spbrgx only (compatible mode), spbrghx value is ignored bit 2 iren: irda ? encoder and decoder enable bit asynchronous mode: 1 = irda encoder and decoder are enabled (asynchronous irda mode is active) 0 = irda encoder and decoder are disabled synchronous mode: (1) no effect on operation. bit 1 wue: wake-up enable bit asynchronous mode: 1 = eusartx will continue to sample the rxx pin ? interrupt is generated on the falling edge; bit is cleared in hardware on following rising edge 0 = rxx pin is not monitored or rising edge detected synchronous mode: unused in this mode. note 1: this feature is only available in asynchronous mode with the 16x clock preset. the 16x clock is present for both the x16 and x64 brg configurations.
? 2012 microchip technology inc. ds30575a-page 415 pic18f97j94 family bit 0 abden: auto-baud detect enable bit asynchronous mode: 1 = enables baud rate measurement on the next character, requires reception of a sync field (55h); cleared in hardware upon completion 0 = baud rate measurement is disabled or has completed synchronous mode: unused in this mode. note 1: this feature is only available in asynchronous mode with the 16x clock preset. the 16x clock is present for both the x16 and x64 brg configurations.
pic18f97j94 family ds30575a-page 416 ? 2012 microchip technology inc. 21.1 baud rate generator (brg) the brg is a dedicated, 8-bit or 16-bit generator that supports both the asynchronous and synchronous modes of the eusartx. by default, the brg operates in 8-bit mode; setting the brg16 bit (baudconx<3>) selects 16-bit mode. the spbrghx:spbrgx register pair controls the period of a free-running timer. in asynchronous mode, bits, brgh (txstax<2>) and brg16 (baudconx<3>), also control the baud rate. in synchronous mode, brgh is ignored. table 21-1 shows the formula for computation of the baud rate for different eusartx modes which only apply in master mode (internally generated clock). given the desired baud rate and f osc , the nearest integer value for the spbrghx:spbrgx registers can be calculated using the formulas in tab le 2 1- 1 . from this, the error in baud rate can be determined. an example calculation is shown in example 21-1 . typical baud rates and error values for the various asynchronous modes are shown in ta b l e 2 1 - 2 . it may be advantageous to use the high baud rate (brgh = 1 ) or the 16-bit brg to reduce the baud rate error, or achieve a slow baud rate for a fast oscillator frequency. writing a new value to the spbrghx:spbrgx registers causes the brg timer to be reset (or cleared). this ensures the brg does not wait for a timer over- flow before outputting the new baud rate. when operated in the synchronous mode, spbrgh:spbrg values of 0000h and 0001h are not supported. in the asynchronous mode, all brg values may be used. 21.1.1 operation in power-managed modes the device clock is used to generate the desired baud rate. when one of the power-managed modes is entered, the new clock source may be operating at a different frequency. this may require an adjustment to the value in the spbrgx register pair. 21.1.2 sampling the data on the rxx pin is sampled three times by a majority detect circuit to determine if a high or a low level is present at the rxx pin. table 21-1: baud rate formulas example 21-1: calculat ing baud rate error configuration bits brg/eusart mode baud rate formula sync brg16 brgh 000 8-bit/asynchronous f osc /[64 (n + 1)] 001 8-bit/asynchronous f osc /[16 (n + 1)] 010 16-bit/asynchronous 011 16-bit/asynchronous f osc /[4 (n + 1)] 10x 8-bit/synchronous 11x 16-bit/synchronous legend: x = don?t care, n = value of spbrghx:spbrgx register pair for a device with f osc of 16 mhz, desired baud rate of 9600, asynchronous mode, and 8-bit brg: desired baud rate = f osc /(64 ([spbrghx:spbrgx] + 1)) solving for spbrghx:spbrgx: x = ((f osc /desired baud rate)/64) ? 1 = ((16000000/9600)/64) ? 1 = [25.042] = 25 calculated baud rate = 16000000/(64 (25 + 1)) = 9615 error = (calculated baud rate ? de sired baud rate)/desired baud rate = (9615 ? 9600)/9600 = 0.16%
? 2012 microchip technology inc. ds30575a-page 417 pic18f97j94 family table 21-2: baud rates for asynchronous modes baud rate (k) sync = 0 , brgh = 0 , brg16 = 0 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3???????????? 1.2 ? ? ? 1.221 1.73 255 1.202 0.16 129 1.201 -0.16 103 2.4 2.441 1.73 255 2.404 0.16 129 2.404 0.16 64 2.403 -0.16 51 9.6 9.615 0.16 64 9.766 1.73 31 9.766 1.73 15 9.615 -0.16 12 19.2 19.531 1.73 31 19.531 1.73 15 19.531 1.73 7 ? ? ? 57.6 56.818 -1.36 10 62.500 8.51 4 52.083 -9.58 2 ? ? ? 115.2 125.000 8.51 4 104.167 -9.58 2 78.125 -32.18 1 ? ? ? baud rate (k) sync = 0 , brgh = 0 , brg16 = 0 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.16 207 0.300 -0.16 103 0.300 -0.16 51 1.2 1.202 0.16 51 1.201 -0.16 25 1.201 -0.16 12 2.4 2.404 0.16 25 2.403 -0.16 12 ? ? ? 9.6 8.929 -6.99 6 ? ? ? ? ? ? 19.2 20.833 8.51 2 ? ? ? ? ? ? 57.6 62.500 8.51 0 ? ? ? ? ? ? 115.2 62.500 -45.75 0 ? ? ? ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 0 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3???????????? 1.2???????????? 2.4 ? ? ? ? ? ? 2.441 1.73 255 2.403 -0.16 207 9.6 9.766 1.73 255 9.615 0.16 129 9.615 0.16 64 9.615 -0.16 51 19.2 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 19.230 -0.16 25 57.6 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 55.555 3.55 8 115.2 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 0 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 ? ? ? ? ? ? 0.300 -0.16 207 1.2 1.202 0.16 207 1.201 -0.16 103 1.201 -0.16 51 2.4 2.404 0.16 103 2.403 -0.16 51 2.403 -0.16 25 9.6 9.615 0.16 25 9.615 -0.16 12 ? ? ? 19.2 19.231 0.16 12 ? ? ? ? ? ? 57.6 62.500 8.51 3 ? ? ? ? ? ? 115.2 125.000 8.51 1 ? ? ? ? ? ?
pic18f97j94 family ds30575a-page 418 ? 2012 microchip technology inc. baud rate (k) sync = 0 , brgh = 0 , brg16 = 1 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.00 8332 0.300 0.02 4165 0.300 0.02 2082 0.300 -0.04 1665 1.2 1.200 0.02 2082 1.200 -0.03 1041 1.200 -0.03 520 1.201 -0.16 415 2.4 2.402 0.06 1040 2.399 -0.03 520 2.404 0.16 259 2.403 -0.16 207 9.6 9.615 0.16 259 9.615 0.16 129 9.615 0.16 64 9.615 -0.16 51 19.2 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 19.230 -0.16 25 57.6 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 55.555 3.55 8 115.2 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 ? ? ? baud rate (k) sync = 0 , brgh = 0 , brg16 = 1 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.04 832 0.300 -0.16 415 0.300 -0.16 207 1.2 1.202 0.16 207 1.201 -0.16 103 1.201 -0.16 51 2.4 2.404 0.16 103 2.403 -0.16 51 2.403 -0.16 25 9.6 9.615 0.16 25 9.615 -0.16 12 ? ? ? 19.2 19.231 0.16 12 ? ? ? ? ? ? 57.6 62.500 8.51 3 ? ? ? ? ? ? 115.2 125.000 8.51 1 ? ? ? ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.00 33332 0.300 0.00 16665 0.300 0.00 8332 0.300 -0.01 6665 1.2 1.200 0.00 8332 1.200 0.02 4165 1.200 0.02 2082 1.200 -0.04 1665 2.4 2.400 0.02 4165 2.400 0.02 2082 2.402 0.06 1040 2.400 -0.04 832 9.6 9.606 0.06 1040 9.596 -0.03 520 9.615 0.16 259 9.615 -0.16 207 19.2 19.193 -0.03 520 19.231 0.16 259 19.231 0.16 129 19.230 -0.16 103 57.6 57.803 0.35 172 57.471 -0.22 86 58.140 0.94 42 57.142 0.79 34 115.2 114.943 -0.22 86 116.279 0.94 42 113.636 -1.36 21 117.647 -2.12 16 baud rate (k) sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.01 3332 0.300 -0.04 1665 0.300 -0.04 832 1.2 1.200 0.04 832 1.201 -0.16 415 1.201 -0.16 207 2.4 2.404 0.16 415 2.403 -0.16 207 2.403 -0.16 103 9.6 9.615 0.16 103 9.615 -0.16 51 9.615 -0.16 25 19.2 19.231 0.16 51 19.230 -0.16 25 19.230 -0.16 12 57.6 58.824 2.12 16 55.555 3.55 8 ? ? ? 115.2 111.111 -3.55 8 ? ? ? ? ? ? table 21-2: baud rates for asynchronous modes (continued)
? 2012 microchip technology inc. ds30575a-page 419 pic18f97j94 family 21.1.3 auto-baud rate detect the enhanced usart module supports the automatic detection and calibration of baud rate. this feature is active only in asynchronous mode and while the wue bit is clear. the automatic baud rate measurement sequence ( figure 21-1 ) begins whenever a start bit is received and the abden bit is set. the calculation is self-averaging. in the auto-baud rate detect (abd) mode, the clock to the brg is reversed. rather than the brg clocking the incoming rxx signal, the rxx signal is timing the brg. in abd mode, the internal baud rate generator is used as a counter to time the bit period of the incoming serial byte stream. once the abden bit is set, the state machine will clear the brg and look for a start bit. the auto-baud rate detect must receive a byte with the value, 55h (ascii ?u?, which is also the lin/j2602 bus sync character), in order to calculate the proper bit rate. the measurement is taken over both a low and a high bit time in order to minimize any effects caused by asymmetry of the incom- ing signal. after a start bit, the spbrgx begins counting up, using the preselected clock source on the first rising edge of rxx. after eight bits on the rxx pin or the fifth rising edge, an accumulated value totalling the proper brg period is left in the spbrghx:spbrgx register pair. once the 5th edge is seen (this should correspond to the stop bit), the abden bit is automatically cleared. if a rollover of the brg occurs (an overflow from ffffh to 0000h), the event is trapped by the abdovf status bit (baudconx<7>). it is set in hardware by brg roll- overs and can be set or cleared by the user in software. abd mode remains active after rollover events and the abden bit remains set ( figure 21-2 ). while calibrating the baud rate period, the brg regis- ters are clocked at 1/8th the preconfigured clock rate. the brg clock will be configured by the brg16 and brgh bits. the brg16 bit must be set to use both spbrg1 and spbrgh1 as a 16-bit counter. this allows the user to verify that no carry occurred for 8-bit modes by checking for 00h in the spbrghx register. refer to table 21-3 for counter clock rates to the brg. while the abd sequence takes place, the eusartx state machine is held in idle. the rcxif interrupt is set once the fifth rising edge on rxx is detected. the value in the rcregx needs to be read to clear the rcxif interrupt. the contents of rcregx should be discarded. table 21-3: brg counter clock rates 21.1.3.1 abd and eusartx transmission since the brg clock is reversed during abd acquisi- tion, the eusartx transmitter cannot be used during abd. this means that whenever the abden bit is set, txregx cannot be written to. users should also ensure that abden does not become set during a transmit sequence. failing to do this may result in unpredictable eusartx operation. note 1: if the wue bit is set with the abden bit, auto-baud rate detection will occur on the byte following the break character. 2: it is up to the user to determine that the incoming character baud rate is within the range of the selected brg clock source. some combinations of oscillator frequency and eusartx baud rates are not possible due to bit error rates. overall system timing and communication baud rates must be taken into consideration when using the auto-baud rate detection feature. 3: to maximize baud rate range, if that feature is used it is recommended that the brg16 bit (baudconx<3>) be set. brg16 brgh brg counter clock 00 f osc /512 01 f osc /128 10 f osc /128 11 f osc /32
pic18f97j94 family ds30575a-page 420 ? 2012 microchip technology inc. figure 21-1: automatic baud rate calculation figure 21-2: brg overflow sequence brg value rxx pin abden bit rcxif bit bit 0 bit 1 (interrupt) read rcregx brg clock start auto-cleared set by user xxxxh 0000h edge #1 bit 2 bit 3 edge #2 bit 4 bit 5 edge #3 bit 6 bit 7 edge #4 001ch note: the abd sequence requires the eusartx module to be configured in asynchronous mode and wue = 0 . spbrgx xxxxh 1ch spbrghx xxxxh 00h edge #5 stop bit start bit 0 xxxxh 0000h 0000h ffffh brg clock abden bit rxx pin abdovf bit brg value
? 2012 microchip technology inc. ds30575a-page 421 pic18f97j94 family 21.2 eusartx asynchronous mode the asynchronous mode of operation is selected by clearing the sync bit (txstax<4>). in this mode, the eusartx uses standard non-return-to-zero (nrz) format (one start bit, eight or nine data bits and one stop bit). the most common data format is 8 bits. an on-chip, dedicated 8-bit/16-bit baud rate generator can be used to derive standard baud rate frequencies from the oscillator. the eusartx transmits and receives the lsb first. the eusartx?s transmitter and receiver are functionally independent but use the same data format and baud rate. the baud rate generator produces a clock, either x16 or x64 of the bit shift rate, depending on the brgh and brg16 bits (txstax<2> and baudconx<3>). parity is not supported by the hardware but can be implemented in software and stored as the 9th data bit. when operating in asynchronous mode, the eusartx module consists of the following important elements: ? baud rate generator ? sampling circuit ? asynchronous transmitter ? asynchronous receiver ? auto-wake-up on sync break character ? 12-bit break character transmit ? auto-baud rate detection 21.2.1 eusartx asynchronous transmitter the eusartx transmitter block diagram is shown in figure 21-3 . the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txregx. the txregx register is loaded with data in software. the tsr register is not loaded until the stop bit has been transmitted from the previous load. as soon as the stop bit is transmitted, the tsr is loaded with new data from the txregx register (if available). once the txregx register transfers the data to the tsr register (occurs in one t cy ), the txregx register is empty and the txxif flag bit is set. this interrupt can be enabled or disabled by setting or clearing the interrupt enable bit, txxie. txxif will be set regardless of the state of txxie; it cannot be cleared in software. txxif is also not cleared immediately upon loading txregx, but becomes valid in the second instruction cycle following the load instruction. polling txxif immediately following a load of txregx will return invalid results. while txxif indicates the status of the txregx regis- ter, another bit, trmt (txstax<1>), shows the status of the tsr register. trmt is a read-only bit which is set when the tsr register is empty. no interrupt logic is tied to this bit so the user has to poll this bit in order to determine if the tsr register is empty. to set up an asynchronous transmission: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing bit, sync, and setting bit, spen. 3. if interrupts are desired, set enable bit, txxie. 4. if 9-bit transmission is desired, set transmit bit, tx9. can be used as address/data bit. 5. enable the transmission by setting bit, txen, which will also set bit, txxif. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit, tx9d. 7. load data to the txregx register (starts transmission). 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 21-3: eusartx transmit block diagram note 1: the tsr register is not mapped in data memory, so it is not available to the user. 2: flag bit, txxif, is set when enable bit, txen, is set. txxif txxie interrupt txen baud rate clk spbrgx baud rate generator tx9d msb lsb data bus txregx register tsr register (8) 0 tx9 trmt spen txx pin pin buffer and control 8 ????????? spbrghx brg16
pic18f97j94 family ds30575a-page 422 ? 2012 microchip technology inc. figure 21-4: asynchronous transmission figure 21-5: asynchronous transmiss ion (back-to-back) word 1 word 1 transmit shift reg start bit bit 0 bit 1 bit 7/8 write to txregx brg output (shift clock) txx (pin) txxif bit (transmit buffer reg. empty flag) trmt bit (transmit shift reg. empty flag) 1 t cy stop bit word 1 transmit shift reg. write to txregx brg output (shift clock) txx (pin) txxif bit (interrupt reg. flag) trmt bit (transmit shift reg. empty flag) word 1 word 2 word 1 word 2 stop bit start bit transmit shift reg. word 1 word 2 bit 0 bit 1 bit 7/8 bit 0 note: this timing diagram shows two consecutive transmissions. 1 t cy 1 t cy start bit
? 2012 microchip technology inc. ds30575a-page 423 pic18f97j94 family 21.2.2 eusartx asynchronous receiver the receiver block diagram is shown in figure 21-6 . the data is received on the rxx pin and drives the data recovery block. the data recovery block is actually a high-speed shifter operating at x16 times the baud rate, whereas the main receive serial shifter operates at the bit rate or at f osc . this mode would typically be used in rs-232 systems. to set up an asynchronous reception: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing bit, sync, and setting bit, spen. 3. if interrupts are desired, set enable bit, rcxie. 4. if 9-bit reception is desired, set bit, rx9. 5. enable the reception by setting bit, cren. 6. flag bit, rcxif, will be set when reception is complete and an interrupt will be generated if enable bit, rcxie, was set. 7. read the rcstax register to get the 9th bit (if enabled) and determine if any error occurred during reception. 8. read the 8-bit received data by reading the rcregx register. 9. if any error occurred, clear the error by clearing enable bit, cren. 10. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. 21.2.3 setting up 9-bit mode with address detect this mode would typically be used in rs-485 systems. to set up an asynchronous reception with address detect enable: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing the sync bit and setting the spen bit. 3. if interrupts are required, set the rcen bit and select the desired priority level with the rcxip bit. 4. set the rx9 bit to enable 9-bit reception. 5. set the adden bit to enable address detect. 6. enable reception by setting the cren bit. 7. the rcxif bit will be set when reception is complete. the interrupt will be acknowledged if the rcxie and gie bits are set. 8. read the rcstax register to determine if any error occurred during reception, as well as read bit 9 of data (if applicable). 9. read rcregx to determine if the device is being addressed. 10. if any error occurred, clear the cren bit. 11. if the device has been addressed, clear the adden bit to allow all received data into the receive buffer and interrupt the cpu. figure 21-6: eusartx receive block diagram x64 baud rate clk baud rate generator rxx pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcregx register fifo interrupt rcxif rcxie data bus 8 ? 64 ? 16 or stop start (8) 7 1 0 rx9 ??????? spbrgx spbrghx brg16 or ? 4
pic18f97j94 family ds30575a-page 424 ? 2012 microchip technology inc. figure 21-7: asynchronous reception 21.2.4 auto-wake-up on sync break character during sleep mode, all clocks to the eusartx are suspended. because of this, the baud rate generator is inactive and a proper byte reception cannot be per- formed. the auto-wake-up feature allows the controller to wake-up due to activity on the rxx/dtx line while the eusartx is operating in asynchronous mode. the auto-wake-up feature is enabled by setting the wue bit (baudconx<1>). once set, the typical receive sequence on rxx/dtx is disabled and the eusartx remains in an idle state, monitoring for a wake-up event independent of the cpu mode. a wake-up event consists of a high-to-low transition on the rxx/dtx line. (this coincides with the start of a sync break or a wake-up signal character for the lin/j2602 protocol.) following a wake-up event, the module generates an rcxif interrupt. the interrupt is generated synchro- nously to the q clocks in normal operating modes ( figure 21-8 ) and asynchronously if the device is in sleep mode ( figure 21-9 ). the interrupt condition is cleared by reading the rcregx register. the wue bit is automatically cleared once a low-to-high transition is observed on the rxx line following the wake-up event. at this point, the eusartx module is in idle mode and returns to normal operation. this signals to the user that the sync break event is over. 21.2.4.1 special considerations using auto-wake-up since auto-wake-up functions by sensing rising edge transitions on rxx/dtx, information with any state changes before the stop bit may signal a false end-of-character (eoc) and cause data or framing errors. to work properly, therefore, the initial character in the transmission must be all ? 0 ?s. this can be 00h (8 bits) for standard rs-232 devices or 000h (12 bits) for the lin/j2602 bus. oscillator start-up time must also be considered, especially in applications using oscillators with longer start-up intervals (i.e., hs or hspll mode). the sync break (or wake-up signal) character must be of sufficient length and be followed by a sufficient interval to allow enough time for the selected oscillator to start and provide proper initialization of the eusartx. start bit bit 7/8 bit 1 bit 0 bit 7/8 bit 0 stop bit start bit start bit bit 7/8 stop bit rxx (pin) rcv buffer reg rcv shift reg read rcv buffer reg rcregx rcxif (interrupt flag) oerr bit cren word 1 rcregx word 2 rcregx stop bit note: this timing diagram shows three words appearing on the rxx input. the rcregx (receive buffer) is read after the third word, causing the oerr (overrun) bit to be set.
? 2012 microchip technology inc. ds30575a-page 425 pic18f97j94 family 21.2.4.2 special considerations using the wue bit the timing of wue and rcxif events may cause some confusion when it comes to determining the validity of received data. as noted, setting the wue bit places the eusartx in an idle mode. the wake-up event causes a receive interrupt by setting the rcxif bit. the wue bit is cleared after this when a rising edge is seen on rxx/dtx. the interrupt condition is then cleared by reading the rcregx register. ordinarily, the data in rcregx will be dummy data and should be discarded. the fact that the wue bit has been cleared (or is still set), and the rcxif flag is set, should not be used as an indicator of the integrity of the data in rcregx. users should consider implementing a parallel method in firmware to verify received data integrity. to assure that no actual data is lost, check the rcidl bit to verify that a receive operation is not in process. if a receive operation is not occurring, the wue bit may then be set just prior to entering the sleep mode. figure 21-8: auto-wake-up bit (wue) timings during no rmal operation figure 21-9: auto-wake-up bit (wue) timings during sleep q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit (1) rxx/dtx line rcxif note 1: the eusartx remains in idle while the wue bit is set. bit set by user cleared due to user read of rcregx auto-cleared q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit (2) rxx/dtx line rcxif cleared due to user read of rcregx sleep command executed note 1: if the wake-up event requires long oscillator warm-up time, the auto-clear of the wue bit can occur before the oscillator is re ady. this sequence should not depend on the presence of q clocks. 2: the eusartx remains in idle while the wue bit is set. sleep ends note 1 auto-cleared bit set by user
pic18f97j94 family ds30575a-page 426 ? 2012 microchip technology inc. 21.2.5 break character sequence the eusartx module has the capability of sending the special break character sequences that are required by the lin/j2602 bus standard. the break character transmit consists of a start bit, followed by twelve ? 0 ? bits and a stop bit. the frame break charac- ter is sent whenever the sendb and txen bits (txstax<3> and txstax<5>, respectively) are set while the transmit shift register is loaded with data. note that the value of data written to txregx will be ignored and all ? 0 ?s will be transmitted. the sendb bit is automatically reset by hardware after the corresponding stop bit is sent. this allows the user to preload the transmit fifo with the next transmit byte following the break character (typically, the sync character in the lin/j2602 specification). note that the data value written to the txregx for the break character is ignored. the write simply serves the purpose of initiating the proper sequence. the trmt bit indicates when the transmit operation is active or idle, just as it does during normal transmis- sion. see figure 21-10 for the timing of the break character sequence. 21.2.5.1 break and sync transmit sequence the following sequence will send a message frame header made up of a break, followed by an auto-baud sync byte. this sequence is typical of a lin/j2602 bus master. 1. configure the eusartx for the desired mode. 2. set the txen and sendb bits to set up the break character. 3. load the txregx with a dummy character to initiate transmission (the value is ignored). 4. write ?55h? to txregx to load the sync character into the transmit fifo buffer. 5. after the break has been sent, the sendb bit is reset by hardware. the sync character now transmits in the preconfigured mode. when the txregx becomes empty, as indicated by the txxif, the next data byte can be written to txregx. 21.2.6 receiving a break character the enhanced usart module can receive a break character in two ways. the first method forces configuration of the baud rate at a frequency of 9/13 the typical speed. this allows for the stop bit transition to be at the correct sampling location (13 bits for break versus start bit and 8 data bits for typical data). the second method uses the auto-wake-up feature described in section 21.2.4 ?auto-wake-up on sync break character? . by enabling this feature, the eusartx will sample the next two transitions on rxx/dtx, cause an rcxif interrupt and receive the next data byte followed by another interrupt. note that following a break character, the user will typically want to enable the auto-baud rate detect feature. for both methods, the user can set the abden bit once the txxif interrupt is observed. figure 21-10: send break character sequence write to txregx brg output (shift clock) start bit bit 0 bit 1 bit 11 stop bit break txxif bit (transmit buffer reg. empty flag) txx (pin) trmt bit (transmit shift reg. empty flag) sendb bit (transmit shift reg. empty flag) sendb sampled here auto-cleared dummy write
? 2012 microchip technology inc. ds30575a-page 427 pic18f97j94 family 21.3 eusartx synchronous master mode the synchronous master mode is entered by setting the csrc bit (txstax<7>). in this mode, the data is transmitted in a half-duplex manner (i.e., transmission and reception do not occur at the same time). when transmitting data, the reception is inhibited and vice versa. synchronous mode is entered by setting bit, sync (txstax<4>). in addition, enable bit, spen (rcstax<7>), is set in order to configure the txx and rxx pins to ckx (clock) and dtx (data) lines, respectively. the master mode indicates that the processor trans- mits the master clock on the ckx line. clock polarity is selected with the txckp bit (baudconx<4>). setting txckp sets the idle state on ckx as high, while clear- ing the bit sets the idle state as low. this option is provided to support microwire devices with this module. 21.3.1 eusartx synchronous master transmission the eusartx transmitter block diagram is shown in figure 21-3 . the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txregx. the txregx register is loaded with data in software. the tsr register is not loaded until the last bit has been transmitted from the previous load. as soon as the last bit is transmitted, the tsr is loaded with new data from the txregx (if available). once the txregx register transfers the data to the tsr register (occurs in one t cy ), the txregx is empty and the txxif flag bit is set. the interrupt can be enabled or disabled by setting or clearing the interrupt enable bit, txxie. txxif is set regardless of the state of enable bit, txxie; it cannot be cleared in software. it will reset only when new data is loaded into the txregx register. while flag bit, txxif, indicates the status of the txregx register, another bit, trmt (txstax<1>), shows the status of the tsr register. trmt is a read-only bit which is set when the tsr is empty. no interrupt logic is tied to this bit, so the user must poll this bit in order to determine if the tsr register is empty. the tsr is not mapped in data memory so it is not available to the user. to set up a synchronous master transmission: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brg16 bit, as required, to achieve the desired baud rate. 2. enable the master synchronous serial port by setting bits, sync, spen and csrc. 3. if interrupts are desired, set enable bit, txxie. 4. if 9-bit transmission is desired, set bit, tx9. 5. enable the transmission by setting bit, txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit, tx9d. 7. start transmission by loading data to the txregx register. 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set.
pic18f97j94 family ds30575a-page 428 ? 2012 microchip technology inc. figure 21-11: synchronous transmission figure 21-12: synchronous transmis sion (through txen) bit 0 bit 1 bit 7 word 1 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1q2 q3 q4 q1 q2 q3 q4 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 bit 2 bit 0 bit 1 bit 7 tx1/ck1 pin write to txreg1 reg tx1if bit (interrupt flag) txen bit ? 1 ? ? 1 ? word 2 trmt bit write word 1 write word 2 note: sync master mode, spbrgx = 0 , continuous transmission of two 8-bit words. this example is equally applicable to eusart2 (tx2/ck2 and rx2/dt2). rx1/dt1 pin (txckp = 0 ) tx1/ck1 pin (txckp = 1 ) rx1/dt1 pin tx1/ck1 pin write to txreg1 reg tx1if bit trmt bit bit 0 bit 1 bit 2 bit 6 bit 7 txen bit note: this example is equally applicable to eusart2 (tx2/ck2 and rx2/dt2).
? 2012 microchip technology inc. ds30575a-page 429 pic18f97j94 family 21.3.2 eusartx synchronous master reception once synchronous mode is selected, reception is enabled by setting either the single receive enable bit, sren (rcstax<5>) or the continuous receive enable bit, cren (rcstax<4>). data is sampled on the rxx pin on the falling edge of the clock. if enable bit, sren, is set, only a single word is received. if enable bit, cren, is set, the reception is continuous until cren is cleared. if both bits are set, then cren takes precedence. to set up a synchronous master reception: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brg16 bit, as required, to achieve the desired baud rate. 2. enable the master synchronous serial port by setting bits, sync, spen and csrc. 3. ensure bits, cren and sren, are clear. 4. if interrupts are desired, set enable bit, rcxie. 5. if 9-bit reception is desired, set bit, rx9. 6. if a single reception is required, set bit, sren. for continuous reception, set bit, cren. 7. interrupt flag bit, rcxif, will be set when recep- tion is complete and an interrupt will be generated if the enable bit, rcxie, was set. 8. read the rcstax register to get the 9th bit (if enabled) and determine if any error occurred during reception. 9. read the 8-bit received data by reading the rcregx register. 10. if any error occurred, clear the error by clearing bit cren. 11. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 21-13: synchronous reception (master mode, sren) cren bit write to bit, sren sren bit rc1if bit (interrupt) read rcreg1 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q2 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 ? 0 ? bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 ? 0 ? q1 q2 q3 q4 note: timing diagram demonstrates sync master mode with bit, sren = 1, and bit, brgh = 0 . this example is equally applicable to eusart2 (tx2/ck2 and rx2/dt2). rx1/dt1 pin tx1/ck1 pin (txckp = 0 ) tx1/ck1 pin (txckp = 1 )
pic18f97j94 family ds30575a-page 430 ? 2012 microchip technology inc. 21.4 eusartx synchronous slave mode synchronous slave mode is entered by clearing bit, csrc (txstax<7>). this mode differs from the synchronous master mode in that the shift clock is sup- plied externally at the ckx pin (instead of being supplied internally in master mode). this allows the device to transfer or receive data while in any low-power mode. 21.4.1 eusartx synchronous slave transmission the operation of the synchronous master and slave modes is identical, except in the case of sleep mode. if two words are written to the txregx and then the sleep instruction is executed, the following will occur: a) the first word will immediately transfer to the tsr register and transmit. b) the second word will remain in the txregx register. c) flag bit, txxif, will not be set. d) when the first word has been shifted out of tsr, the txregx register will transfer the second word to the tsr and flag bit, txxif, will now be set. e) if enable bit, txxie, is set, the interrupt will wake the chip from sleep. if the global interrupt is enabled, the program will branch to the interrupt vector. to set up a synchronous slave transmission: 1. enable the synchronous slave serial port by setting bits, sync and spen, and clearing bit, csrc. 2. clear bits, cren and sren. 3. if interrupts are desired, set enable bit, txxie. 4. if 9-bit transmission is desired, set bit, tx9. 5. enable the transmission by setting enable bit, txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit, tx9d. 7. start transmission by loading data to the txregx register. 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. 21.4.2 eusartx synchronous slave reception the operation of the synchronous master and slave modes is identical, except in the case of sleep, or any idle mode and bit, sren, which is a ?don?t care? in slave mode. if receive is enabled by setting the cren bit prior to entering sleep or any idle mode, then a word may be received while in this low-power mode. once the word is received, the rsr register will transfer the data to the rcregx register. if the rcxie enable bit is set, the interrupt generated will wake the chip from the low-power mode. if the global interrupt is enabled, the program will branch to the interrupt vector. to set up a synchronous slave reception: 1. enable the master synchronous serial port by setting bits, sync and spen, and clearing bit, csrc. 2. if interrupts are desired, set enable bit, rcxie. 3. if 9-bit reception is desired, set bit, rx9. 4. to enable reception, set enable bit, cren. 5. flag bit, rcxif, will be set when reception is complete. an interrupt will be generated if enable bit, rcxie, was set. 6. read the rcstax register to get the 9th bit (if enabled) and determine if any error occurred during reception. 7. read the 8-bit received data by reading the rcregx register. 8. if any error occurred, clear the error by clearing bit, cren. 9. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set.
? 2012 microchip technology inc. ds30575a-page 431 pic18f97j94 family 21.5 infrared support this module provides support for two types of infrared usart port implementations: ? irda clock output to support an external irda encoder/decoder device ? full implementation of the irda encoder and decoder as part of the usart logic since the 16x clock is required to perform the irda encoding, both by this module and the external trans- mitter, this feature only works in the 16x baud rate mode and is not available in the 4x mode. 21.5.1 external irda support ? irda clock output the 16x baud clock is provided on the bclk (baud clock) pin if the eusartx is enabled (spen = 1 ); it is configured for asynchronous mode (sync = 0 ) when clock source select is active (csrc = 1 ). note that the bclk can be active in regular or irda mode (iren bit is ignored). 21.5.1.1 bclk output the timing of the baud clock (bclk) output is inde- pendent of the 16x or 4x baud rate mode, resulting in the same output for a particular brg value (since the 4x mode is four times faster, but has four times less pulses per period). when the bclk pin mode is active, the rxx baud rate generator will be turned on, independent of a txx or rxx operation. this will cause the rxx stream to synchronize to the already running rxx baud clock. this is acceptable only when bclk is enabled for use. the bclk output goes inactive and stays low during sleep mode. the bclk pin is taken over by the eusartx module and forced as an output, irrespective of port latch and tris latch bits. bclk remains an output as long as usart is kept enabled in this mode. figure 21-14: bclk output vs. brg programming (brg + 1) [int(brg + 1)/2] 16x or 4x clock bclk @ brg = 0 bclk @ brg = 1 bclk @ brg = 2 bclk @ brg = 3 bclk @ brg = 4 bclk @ brg = 5 bclk @ brg = n note: the bclk has 50% duty cycle only for odd brg values. th is is due to having all bclk edges synchronous to the rising edge of the 16x/4x clock.
pic18f97j94 family ds30575a-page 432 ? 2012 microchip technology inc. 21.5.2 built-in irda encoder and decoder the built-in irda encoder and decoder functionality is enabled using the iren bit in the baudconx register while the module is in asynchronous mode (sync = 0 ). when enabled (iren = 1 ), the receive pin (rxx) acts as the input from the infrared receiver. the transmit pin (txx) acts as the output to the infra- red transmitter. the 16x clock must be available for this feature to work properly. the irda feature cannot be enabled for synchronous modes (sync = 1 ). 21.5.2.1 irda encoder function the encoder works by taking the serial data from the usart and replacing it as follows: ? transmit bit data of ? 1 ? gets encoded as ? 0 ? for the entire 16 periods of the 16x baud clock ? transmit bit data of ? 0 ? gets encoded as ? 0 ? for the first 7 periods of the 16x baud clock, then as ? 1 ? for the next 3 periods, and as ? 0 ? for the remaining 6 periods see figure 21-15 and figure 21-17 for details. 21.5.2.2 irda transmit polarity the irda transmit polarity is selected using the txckp bit. this bit only affects the transmit encoder and does not affect the receiver. when txckp = 0 , the idle state of the txx line is ? 0 ? (see figure 21-15 ). when txckp = 1 , the idle state of the txx line is ? 1 ? (see figure 21-16 ). figure 21-15: irda ? encoding scheme figure 21-16: inverted irda ? encoding (txckp = 1 ) figure 21-17: ? 0 ? bit data irda ? encoding scheme txx data txx (tx_out) txx data txx (tx_out) start of start of ? 0 ? transmit bit 16x baud clock txx data txx (tx_out) 8th period 11th period
? 2012 microchip technology inc. ds30575a-page 433 pic18f97j94 family 21.5.2.3 irda decoder function the decoder works by taking the serial data from the rxx pin and replacing it with the decoded data stream. the stream is decoded based on falling edge detection of the rxx input. each falling edge of rxx causes the decoded data to be driven low for 16 periods of the 16x baud clock. if another falling edge has been detected by the time the 16 periods expire, the decoded data remains low for another 16 periods. if no falling edge was detected, the decoded data is driven high. note that the data stream into the device is shifted anywhere from 7 to 8 periods of the 16x baud clock from the actual message source. the one clock uncer- tainty is due to the clock edge resolution. see figure 21-18 for details. 21.5.2.4 irda receive polarity the irda receive polarity is selected using the rxdtp bit. this bit only affects the receive encoder and does not affect the transmitter. when rxdtp = 0 , the idle state of the rxx line is ? 1 ? (see figure 21-18 ). when rxdtp = 1 , the idle state of the rxx line is ? 0 ? (see figure 21-19 ). 21.5.2.5 clock jitter due to jitter or slight frequency differences between devices, it is possible for the next falling bit edge to be missed for one of the 16x periods. in that case, one clock-wide pulse appears on the decoded data stream. since the eusartx performs a majority detect around the bit center, this does not cause erroneous data. see figure 21-20 for details. figure 21-18: macro view of irda ? decoding scheme (rxdtp = 0 ) figure 21-19: inverted polarity decoding results (rxdtp = 1 ) figure 21-20: clock jitter causing a pulse between consecutive zeros 16 periods 16 periods 16 periods 16 periods 16 periods start brg t irdel before irda encoder rxx (rx_in) decoded data (transmitting device) 16 periods 16 periods 16 periods 16 periods 16 periods start brg t irdel before irda encoder rxx (rx_in) decoded data (transmitting device) 16 periods 16 periods extra pulse will be ignored rxx (rx_in) decoded data
pic18f97j94 family ds30575a-page 434 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 435 pic18f97j94 family 22.0 12-bit a/d converter with threshold scan the 12-bit a/d converter has the following key features: ? successive approximation register (sar) conversion ? conversion speeds of up to 200 ksps at 12 bits and 500 ksps at 10 bits ? up to 32 analog input channels (internal and external) ? selectable 10-bit or 12-bit (default) conversion ? resolution ? multiple internal reference input channels ? external voltage reference input pins ? unipolar differential sample-and-hold (s/h) amplifier ? automated threshold scan and compare opera- tion to pre-evaluate up to 26 conversion results ? selectable conversion trigger source ? fixed length (one word per channel), configurable conversion result buffer ? four options for results alignment ? configurable interrupt generation ? operation during cpu sleep and idle modes the 12-bit a/d converter module is an enhanced version of the 10-bit module offered in some pic18 devices. both modules are successive approximation register (sar) converters at their cores, surrounded by a range of hardware features for flexible configura- tion. this version of the module extends functionality by providing 12-bit resolution, a wider range of automatic sampling options, tighter integration with other analog modules, such as the ctmu, and a configurable results buffer. this module also includes a unique threshold detect feature that allows the module itself to make simple decisions based on the conversion results. as before, an internal sample-and-hold (s/h) amplifier acquires a sample of an input signal, then holds that value constant during the conversion process. a com- bination of input multiplexers selects the signal to be converted from up to 32 analog inputs, both external (analog input pins) and internal (e.g., on-chip voltage references and other analog modules). the whole mul- tiplexer path includes provisions for differential analog input, although, with a limited number of negative input pins. the sampled voltage is held and converted to a digital value, which strictly speaking, represents the ratio of that input voltage to a reference voltage. configuration choices allow connection of an external reference or use of the device power and ground (av dd and av ss ). reference and input signal pins are assigned differently depending on the particular device. an array of timing and control selections allow the user to create flexible scanning sequences. conversions can be started individually by program control, continu- ously free-running or triggered by selected hardware events. a single channel may be repeatedly converted. alternate conversions may be performed on two chan- nels, or any or all of the channels may be sequentially scanned and converted according to a user-defined bit map. the resulting conversion output is a 12-bit digital number, which can be signed or unsigned, left or right justified. (in some devices, a user-selectable resolution of 10 bits is available; in other devices, 12-bit resolution is the only option available.) conversions are automatically stored in a dedicated buffer, allowing for multiple successive readings to be taken before software service is needed. the buffer can be configured to function as a fifo buffer or as a channel indexed buffer. in fifo mode, the buffer can be split into two equal sections for simultaneous con- version and read operations. in indexed mode, the buf- fer can use the threshold scan feature to determine if a conversion meets specific, user-defined criteria, stor- ing or discarding the converted value as appropriate, and then set semaphore flags to indicate the event. this allows conversions to occur in low-power modes when the cpu is inactive, waking the device only when specific conditions have occurred. the module sets its interrupt flag after a selectable number of conversions, when the buffer can be read, or after a successful threshold detect comparison. after the interrupt, the sequence restarts at the beginning of the buffer. when the interrupt flag is set, according to the earlier selection, scan selections and the output buffer pointer return to their starting positions. during sleep or idle mode, the a/d can wake-up at pre- configured intervals while the device maintains a low-power mode. if threshold conditions have not been met on any of the conversions, the module will return to a low-power mode. the a/d module provides configuration to directly inter- act with the ctmu on specific input channels. this allows the ctmu to automatically turn on only when requested directly by the a/d, even though the rest of the device stays in sleep mode. a simplified block diagram for the module is shown in figure 22-1 .
pic18f97j94 family ds30575a-page 436 ? 2012 microchip technology inc. figure 22-1: 12-bit a/d converter block diagram (pic18f97j94 family) note 1: an16 through an23 are implemented on 80-pin and 100-pin devices only. comparator 12-bit sar conversion logic v ref + dac an(n-1) ann (1) an8 an9 an4 an5 an6 an7 an0 an1 an2 an3 v ref - sample control s/h av ss av dd adc1buf0: adc1bufn (3) ad1con1 ad1con2 ad1con3 ad1chs ad1chitl ad1chith control logic data formatting input mux control conversion control pin config. control internal data bus 16 v r + v r - mux a mux b v inh v inl v inh v inh v inl v inl v r + v r - v r select v bg (2) v bg /6 (2) ad1cssl ctmu (2) v ddcore (2) av ss (2) av dd (2) ad1con5 v bg /2 (2) v bg ad1cssh ad1ctmenl ad1ctmenh ad1dmbuf ad1con4
? 2012 microchip technology inc. ds30575a-page 437 pic18f97j94 family 22.1 registers the 12-bit a/d converter module uses up to 75 registers for its operation. all registers are mapped in the data memory space. 22.1.1 control registers depending on the specific device, the module has up to twelve control and status registers: ? adcon1h/l: a/d control registers ? adcon2h/l: a/d control registers ? adcon3h/l: a/d control registers ? adcon5h/l: a/d control registers ? adchs0h/l: a/d input channel select registers ? adchith1h/l and adchith0h/l: a/d scan compare hit registers ? adcss1h/l and adcss0h/l: a/d input scan select registers ? adctmuen1h/l and adctmuen0h/l: ctmu enable register the adcon1h/l, adcon2h/l and adcon3h/l reg- isters control the overall operation of the a/d module. this includes enabling the module, configuring the con- version clock and voltage reference sources, selecting the sampling and conversion triggers, and manually controlling the sample/convert sequences. the adcon5h/l registers specifically controls features of threshold detect operation, including its functioning in power-saving modes. the adchs0h/l registers selects the input channels to be connected to the s/h amplifier. it also allows the choice of input multiplexers and the selection of a reference source for differential sampling. the adchith1h/l and adchith0h/l registers are semaphore registers used with threshold detect operations. the status of individual bits, or bit pairs in some cases, indicate if a match condition has occurred. their use is described in more detail in section 22.7 ?threshold detect operation?. adchith0h/l is always implemented, whereas adchith1h/l may not be implemented in devices with 16 channels or less. the adcss0h/l/l registers select the channels to be included for sequential scanning. the adctmuen1h/l/l registers select the channel(s) to be used by the ctmu during conversions. selecting a particular channel allows the a/d converter to control the ctmu (particularly, its current source) and read its data through that channel. adctmuen0h/l is always implemented, whereas adctmuen1h/l may not be implemented in devices with 16 channels or less. 22.1.2 a/d result buffers the module incorporates a multi-word, dual port ram, called adcbuf. the buffer is composed of at least the same number of word locations as there are external analog channels for a particular device, with a maximum number of 26. the number of buffer addresses is always even. each of the locations is mapped into the data memory space and is separately addressable.the buffer locations are referred to as adcbuf0h/l through adcbufnh/l (up to 26). the a/d result buffers are both readable and writable. when the module is active (adcon1h<7> = 1 ), the buffers are read-only, and store the results of a/d conversions. when the module is inactive (adcon1h<7> = 0 ), the buffers are both readable and writable. in this state, writing to a buffer location programs a conversion threshold for threshold detect operations, as described in section 22.7.2 ?setting comparison thresholds?.
pic18f97j94 family ds30575a-page 438 ? 2012 microchip technology inc. register 22-1: ancon1: analog select control register 1 (for an7-an0) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ansel7 ansel6 ansel5 ansel4 a nsel3 ansel2 ansel1 ansel0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ansel7: pin rg0 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 6 ansel6: pin rf2 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 5 ansel5: pin ra5 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 4 ansel4: pin ra4 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 3 ansel3: pin ra3 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 2 ansel2: pin ra2 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 1 ansel1: pin ra1 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 0 ansel0: pin ra0 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port
? 2012 microchip technology inc. ds30575a-page 439 pic18f97j94 family register 22-2: ancon2: analog select control register 2 (for an15-an8) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ansel15 ansel14 ansel13 ansel12 ansel11 ansel10 ansel9 ansel8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ansel15: pin rg4 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 6 ansel14: pin rg3 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 5 ansel13: pin rg2 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 4 ansel12: pin rg1 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 3 ansel11: pin rf7 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 2 ansel10: pin rf6 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 1 ansel9: pin rf5 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port bit 0 ansel8: pin rc2 analog enable bit 1 = pin configured as an analog channel ? digital input is disabled and reads ? 0 ? 0 = pin configured as a digital port
pic18f97j94 family ds30575a-page 440 ? 2012 microchip technology inc. register 22-3: ancon3: analog select control register 3 (for an23-an16) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ansel23 ansel22 ansel21 ansel20 ansel19 ansel18 ansel17 ansel16 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ansel23: pin rh7 analog enable 1 = pin configured as an analog channel ? digital input disabled and reads ? 0 ? 0 = pin configured as a digital port bit 6 ansel22: pin rh6 analog enable 1 = pin configured as an analog channel ? digital input disabled and reads ? 0 ? 0 = pin configured as a digital port bit 5 ansel21: pin rh5 analog enable 1 = pin configured as an analog channel ? digital input disabled and reads ? 0 ? 0 = pin configured as a digital port bit 4 ansel20: pin rh4 analog enable 1 = pin configured as an analog channel ? digital input disabled and reads ? 0 ? 0 = pin configured as a digital port bit 3 ansel19: pin rh3 analog enable 1 = pin configured as an analog channel ? digital input disabled and reads ? 0 ? 0 = pin configured as a digital port bit 2 ansel18: pin rh2 analog enable 1 = pin configured as an analog channel ? digital input disabled and reads ? 0 ? 0 = pin configured as a digital port bit 1 ansel17: pin rh1 analog enable 1 = pin configured as an analog channel ? digital input disabled and reads ? 0 ? 0 = pin configured as a digital port bit 0 ansel16: pin rh0 analog enable 1 = pin configured as an analog channel ? digital input disabled and reads ? 0 ? 0 = pin configured as a digital port
? 2012 microchip technology inc. ds30575a-page 441 pic18f97j94 family register 22-4: adcon1h: a/d control register 1 high r/w-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 adon ? ? ? ?mode12form1form0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 adon: a/d operating mode bit 1 = a/d converter module is operating 0 = a/d converter is off bit 6-3 unimplemented: read as ? 0 ? bit 2 mode12: 12-bit operation mode bit 1 = 12-bit a/d operation 0 = 10-bit a/d operation bit 1-0 form<1:0>: data output format bits (see following formats) 11 = fractional result, signed, left-justified 10 = absolute fractional result, unsigned, left-justified 01 = decimal result, signed, right-justified 00 = absolute decimal result, unsigned, right-justified
pic18f97j94 family ds30575a-page 442 ? 2012 microchip technology inc. register 22-5: adcon1l: a/d control register 1 low r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0, hsc r/c-0, hsc ssrc3 ssrc2 ssrc1 ssrc0 ? asam samp done bit 7 bit 0 legend: c = clearable bit u = unimplemented bit, read as ?0? r = readable bit w = writable bit hsc = hardware settable/clearable bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 ssrc<3:0>: sample clock source select bits 1xxx = unimplemented, do not use 0111 = the samp bit is cleared after samc<4:0> number of t ad clocks following the samp bit being set (auto-convert mode); no extended sample time is present 0110 = unimplemented 0101 =tmr1 0100 =ctmu 0011 =tmr5 0010 =tmr3 0001 =int0 0000 = the samp bit must be cleared by software to start conversion bit 3 unimplemented: read as ? 0 ? bit 2 asam: a/d sample auto-start bit 1 = sampling begins immediately after last conversion; samp bit is auto-set 0 = sampling begins when samp bit is manually set bit 1 samp: a/d sample enable bit 1 = a/d sample-and-hold amplifiers are sampling 0 = a/d sample-and-hold amplifiers are holding bit 0 done: a/d conversion status bit 1 = a/d conversion cycle has completed 0 = a/d conversion has not started or is in progress
? 2012 microchip technology inc. ds30575a-page 443 pic18f97j94 family register 22-6: adcon2h: a/d control register 2 high r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 pvcfg1 pvcfg0 nvcfg0 offcal bufregen cscna ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 pvcfg<1:0>: converter positive voltage reference configuration bits 1x = unimplemented, do not use 01 =external v ref + 00 =av dd bit 5 nvcfg0: converter negative voltage reference configuration bit 1 =external v ref - 0 =av ss bit 4 offcal: offset calibration mode select bit 1 = inverting and non-inverting inputs of channel sample-and-hold are connected to av ss 0 = inverting and non-inverting inputs of channel sample-and-hold are connected to normal inputs bit 3 bufregen: a/d buffer register enable bit 1 = conversion result is loaded into the buffer location determined by the converted channel 0 = a/d result buffer is treated as a fifo bit 2 cscna: scan input selections for ch0+ during sample a bit 1 =scans inputs 0 = does not scan inputs bit 1-0 unimplemented: read as ? 0 ?
pic18f97j94 family ds30575a-page 444 ? 2012 microchip technology inc. register 22-7: adcon2l: a/d control register 2 low r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 bufs ( 1 ) smpi4 smpi3 smpi2 smpi1 smpi0 bufm ( 1 ) alts bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 bufs: buffer fill status bit ( 1 ) 1 = a/d is filling the upper half of the buffer; user should access data in the lower half 0 = a/d is filling the lower half of the buffer; user should access data in the upper half bit 6-2 smpi<4:0>: interrupt sample increment rate select bits selects the number of sample/conversions per each interrupt. 11111 = interrupt/address increment at the completion of conversion for each 32nd sample 11110 = interrupt/address increment at the completion of conversion for each 31st sample ????? 00001 = interrupt/address increment at the completion of conversion for every other sample 00000 = interrupt/address increment at the completion of conversion for each sample bit 1 bufm: buffer fill mode select bit ( 1 ) 1 = a/d buffer is two, 13-word buffers, starting at adc1buf0 and adc1buf12, and sequential conversions fill the buffers alternately (split mode) 0 = a/d buffer is a single, 26-word buffer and fills sequentially from adc1buf0 (fifo mode) bit 0 alts: alternate input sample mode select bit 1 = uses channel input selects for sample a on first sample and sample b on next sample 0 = always uses channel input selects for sample a note 1: these bits are only applicable when the buffer is used in fifo mode (bufregen = 0 ). in addition, bufs is only used when bufm = 1 .
? 2012 microchip technology inc. ds30575a-page 445 pic18f97j94 family register 22-8: adcon3h: a/d control register 3 high r/w-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 adrc extsam pumpen samc4 samc3 samc2 samc1 samc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 adrc: a/d conversion clock source bit 1 = rc clock 0 = clock derived from system clock bit 6 extsam: extended sampling time bit 1 = a/d is still sampling after samp = 0 0 = a/d is finished sampling bit 5 pumpen: charge pump enable bit 1 = charge pump for switches is enabled 0 = charge pump for switches is disabled bit 4-0 samc<4:0>: auto-sample time select bits 11111 = 31 t ad ????? 00001 =1 t ad 00000 = 0 t ad register 22-9: adcon3l: a/d control register 3 low r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 adcs7 adcs6 adcs5 adcs4 adcs3 adcs2 adcs1 adcs0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 adcs<7:0>: a/d conversion clock select bits ((adcs<7:0> + 1) t cy ) = t ad 11111111 ????? = reserved 01000000 00111111 = 64 t cy =t ad ????? 00000001 = 2 t cy =t ad 00000000 = t cy =t ad
pic18f97j94 family ds30575a-page 446 ? 2012 microchip technology inc. register 22-10: adcon5h: a/ d control register 5 high r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 asena lpena ctmureq ? ? ? asintmd1 asintmd0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 asena: auto-scan enable bit 1 = auto-scan is enabled 0 = auto-scan is disabled bit 6 lpena: low-power enable bit 1 = low power is enabled after scan 0 = full power is enabled after scan bit 5 ctmureq: ctmu request bit 1 = ctmu is enabled when the a/d is enabled and active 0 = ctmu is not enabled by the a/d bit 4-2 unimplemented: read as ? 0 ? bit 1-0 asintmd<1:0>: auto-scan (threshold detect) interrupt mode bits 11 = interrupt after threshold detect sequence completed and valid compare has occurred 10 = interrupt after valid compare has occurred 01 = interrupt after threshold detect sequence completed 00 = no interrupt
? 2012 microchip technology inc. ds30575a-page 447 pic18f97j94 family register 22-11: adcon5l: a/ d control register 5 low u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? ? wm1 wm0 cm1 cm0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: read as ? 0 ? bit 3-2 wm<1:0>: write mode bits 11 = reserved 10 = auto-compare only (conversion results are not saved, but interrupts are generated when a valid match occurs, as defined by the cm<1:0> and asintmd<1:0> bits) 01 = convert and save (conversion results are saved to locations as determined by the register bits when a match occurs, as defined by the cmx bits) 00 = legacy operation (conversion data is saved to a location determined by the buffer register bits) bit 1-0 cm<1:0>: compare mode bits 11 = outside window mode (valid match occurs if the conversion result is outside of the window, defined by the corresponding buffer pair) 10 = inside window mode (valid match occurs if the conversion result is inside the window, defined by the corresponding buffer pair) 01 = greater than mode (valid match occurs if the result is greater than the value in the corresponding buffer register) 00 = less than mode (valid match occurs if the result is less than the value in the corresponding buffer register)
pic18f97j94 family ds30575a-page 448 ? 2012 microchip technology inc. register 22-12: adchs0h: a/d sample select register 0 high r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ch0nb2 ch0nb1 ch0nb0 ch0sb4 ch0sb3 ch0sb2 ch0sb1 ch0sb0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 ch0nb<2:0>: sample b channel 0 negative input select bits 1xx = unimplemented 011 = unimplemented 010 =an1 001 = unimplemented 000 =v ref -/av ss bit 4-0 ch0sb<4:0>: sample b channel 0 positive input select bits 11111 =v bat /2 ( 1 ) 11110 =av dd ( 1 ) 11101 =av ss ( 1 ) 11100 = band gap reference (v bg ) ( 1 ) 11011 =v bg /2 ( 1 ) 11010 =v bg /6 ( 1 ) 11001 =ctmu 11000 = ctmu temperature sensor input (does not require adctmuen1h<0> to be set) 10111 =an23 ( 2 ) 10110 =an22 ( 2 ) 10101 =an21 ( 2 ) 10100 =an20 ( 2 ) 10011 =an19 ( 2 ) 10010 =an18 ( 2 ) 10001 =an17 ( 2 ) 10000 =an16 ( 2 ) 01111 =an15 01110 =an14 01101 =an13 01100 =an12 01011 =an11 01010 =an10 01001 =an9 01000 =an8 00111 =an7 00110 =an6 00101 =an5 00100 =an4 00011 =an3 00010 =an2 00001 =an1 00000 =an0 note 1: these input channels do not have corresponding memory mapped result buffers. 2: these channels are implemented in 80-pin and 100-pin devices only.
? 2012 microchip technology inc. ds30575a-page 449 pic18f97j94 family register 22-13: adchs0l: a/d sample select register 0 low r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ch0na2 ch0na1 ch0na0 ch0sa4 ch0sa3 ch0sa2 ch0sa1 ch0sa0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 ch0na<2:0>: sample a channel 0 negative input select bits 1xx = unimplemented 011 = unimplemented 010 =an1 001 = unimplemented 000 =v ref -/av ss bit 4-0 ch0sa<4:0>: sample a channel 0 positive input select bits 11111 =v bat /2 ( 1 ) 11110 =av dd ( 1 ) 11101 =av ss ( 1 ) 11100 = band gap reference (v bg ) ( 1 ) 11011 =v bg /2 ( 1 ) 11010 =v bg /6 ( 1 ) 11001 =ctmu 11000 = ctmu temperature sensor input (does not require adctmuen1h<0> to be set) 10111 =an23 ( 2 ) 10110 =an22 ( 2 ) 10101 =an21 ( 2 ) 10100 =an20 ( 2 ) 10011 =an19 ( 2 ) 10010 =an18 ( 2 ) 10001 =an17 ( 2 ) 10000 =an16 ( 2 ) 01111 =an15 01110 =an14 01101 =an13 01100 =an12 01011 =an11 01010 =an10 01001 =an9 01000 =an8 00111 =an7 00110 =an6 00101 =an5 00100 =an4 00011 =an3 00010 =an2 00001 =an1 00000 =an0 note 1: these input channels do not have corresponding memory mapped result buffers. 2: these channels are implemented in 80-pin and 100-pin devices only.
pic18f97j94 family ds30575a-page 450 ? 2012 microchip technology inc. register 22-14: adhit1h: a/d scan compare hit register 1 high (high word) u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? chh30 chh29 chh28 chh27 chh26 chh25 chh24 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-0 chh<30:24>: a/d compare hit bits if cm<1:0> = 11 : 1 = a/d result buffer n has been written with data or a match has occurred 0 = a/d result buffer n has not been written with data for all other valu es of cm<1:0>: 1 = a match has occurred on a/d result channel n 0 = no match has occurred on a/d result channel n register 22-15: adhit1l: a/d scan compare hit register 1 low (low word) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 chh23 chh22 chh21 chh20 chh19 chh18 chh17 chh16 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 chh<23:16>: a/d compare hit bits if cm<1:0> = 11 : 1 = a/d result buffer n has been written with data or a match has occurred 0 = a/d result buffer n has not been written with data for all other valu es of cm<1:0>: 1 = a match has occurred on a/d result channel n 0 = no match has occurred on a/d result channel n
? 2012 microchip technology inc. ds30575a-page 451 pic18f97j94 family register 22-16: adhit0h: a/d scan compare hit register 0 high (high word) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 chh15 chh14 chh13 chh12 chh11 chh10 chh9 chh8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 chh<15:8>: a/d compare hit bits if cm<1:0> = 11 : 1 = a/d result buffer n has been written with data or a match has occurred 0 = a/d result buffer n has not been written with data for all other values of cm<1:0>: 1 = a match has occurred on a/d result channel n 0 = no match has occurred on a/d result channel n register 22-17: adhit0l: a/d scan compare hit register 0 low (low word) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 chh7 chh6 chh5 chh4 chh3 chh2 chh1 chh0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 chh<7:0>: a/d compare hit bits if cm<1:0> = 11 : 1 = a/d result buffer n has been written with data or a match has occurred 0 = a/d result buffer n has not been written with data for all other values of cm<1:0>: 1 = a match has occurred on a/d result channel n 0 = no match has occurred on a/d result channel n
pic18f97j94 family ds30575a-page 452 ? 2012 microchip technology inc. register 22-18: adcss1h: a/d input scan select register 1 high (high word) u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? css30 css29 css28 css27 css26 css25 css24 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-0 css<30:24>: a/d input scan selection bits 1 = includes corresponding channel for input scan 0 = skips channel for input scan register 22-19: adcss1l: a/d input scan select register 1 low (low word) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 css23 css22 css21 css20 css19 css18 css17 css16 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-0 css<23:16>: a/d input scan selection bits 1 = includes corresponding channel for input scan 0 = skips channel for input scan
? 2012 microchip technology inc. ds30575a-page 453 pic18f97j94 family register 22-20: adcss0h: a/d input scan select register 0 high (high word) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 css15 css14 css13 css12 css11 css10 css9 css8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 css<15:8>: a/d input scan selection bits 1 = includes corresponding channel for input scan 0 = skips channel for input scan register 22-21: adcss0l: a/d input scan select register 0 low (low word) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 css7 css6 css5 css4 css3 css2 css1 css0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 css<7:0>: a/d input scan selection bits 1 = includes corresponding channel for input scan 0 = skips channel for input scan
pic18f97j94 family ds30575a-page 454 ? 2012 microchip technology inc. register 22-22: adctmuen1h: ctmu e nable register 1 high (high word) ( 1 ) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ctmuen30 ctmuen29 ctmuen28 ctmuen27 ctmuen26 ctmuen25 ctmuen24 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-0 ctmuen<30:24>: ctmu enabled during conversion bits 1 = ctmu is enabled and connected to the selected channel during conversion 0 = ctmu is not connected to this channel note 1: the actual number of channels available depends on which channels are implemented on a specific device; refer to the device data sheet for details. unimplemented channels are read as ? 0 ?. register 22-23: adctmuen1l: ctmu enable register 1 low (low word) ( 1 ) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ctmuen23 ctmuen22 ctmuen21 ctmuen20 ctmuen19 ctmuen18 ctmuen17 ctmuen16 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-0 ctmuen<23:16>: ctmu enabled during conversion bits 1 = ctmu is enabled and connected to the selected channel during conversion 0 = ctmu is not connected to this channel note 1: the actual number of channels available depends on which channels are implemented on a specific device; refer to the device data sheet for details. unimplemented channels are read as ? 0 ?.
? 2012 microchip technology inc. ds30575a-page 455 pic18f97j94 family register 22-24: adctmuen0h: ctmu e nable register 0 high (high word) ( 1 ) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ctmuen15 ctmuen14 ctmuen13 ctmuen12 ctmuen11 ctmuen10 ctmuen9 ctmuen8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 ctmuen<15:8>: ctmu enabled during conversion bits 1 = ctmu is enabled and connected to the selected channel during conversion 0 = ctmu is not connected to this channel note 1: the actual number of channels available depends on which channels are implemented on a specific device; refer to the device data sheet for details. unimplemented channels are read as ? 0 ?. register 22-25: adctmuen0l: ctmu enable register 0 low (low word) ( 1 ) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ctmuen7 ctmuen6 ctmuen5 ctmuen4 ctmuen3 ctmuen2 ctmuen1 ctmuen0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 ctmuen<7:0>: ctmu enabled during conversion bits 1 = ctmu is enabled and connected to the selected channel during conversion 0 = ctmu is not connected to this channel note 1: the actual number of channels available depends on which channels are implemented on a specific device; refer to the device data sheet for details. unimplemented channels are read as ? 0 ?.
pic18f97j94 family ds30575a-page 456 ? 2012 microchip technology inc. 22.2 a/d terminology and conversion sequence sample time is the time that the a/d module's s/h amplifier is connected to the analog input pin. the sam- ple time may be started and ended automatically by the a/d converter's hardware or under direct program con- trol. there is a minimum sample time to ensure that the s/h amplifier will give sufficient accuracy for the a/d conversion. the conversion trigger ends the sampling time and begins an a/d conversion or a repeating sequence. the conversion trigger sources can be taken from a variety of hardware sources or can be controlled directly in software. one of the conversion trigger options is an auto-conversion, which uses a counter and the a/d clock to set the time between auto-conver- sions. the auto-sample mode and auto-conversion trigger can be used together to provide continuous, automatic conversions without software intervention. when automatic sampling is used, an extended sam- pling interval is extended between the time the sam- pling ends and the conversion starts. conversion time is the time required for the a/d converter to convert the voltage held by the s/h ampli- fier. an a/d conversion requires one a/d clock cycle (tad) to convert each bit of the result, plus two addi- tional clock cycles, or a total of 14 tad cycles for a 12-bit conversion. when the conversion is complete, the result is loaded into one of the a/d result buffers. the s/h can be reconnected to the input pin and a cpu interrupt may be generated. the sum of the sample time(s) and the a/d conversion time provides the total a/d sequence time. figure 22-2 shows the basic conversion sequence and the relationship between intervals. figure 22-2: a/d sample/convert sequence sample time a/d conversion time total a/d sequence time s/h amplifier is connected to the analog input pin for sampling. input disconnected; s/h amplifier holds signal. conversion trigger starts a/d conversion. conversion complete, result is loaded into a/d buffer register. interrupt is generated (optional). extended sampling time (1) sampling ends (manual or automatic trigger). total a/d sample time note 1: in automatic sampling modes, extended sampling time is added to the sequence when the value for the auto-sampling time is greater than 0. otherwise, sampli ng ends and conversion starts whenever the samp bit is cleared.
? 2012 microchip technology inc. ds30575a-page 457 pic18f97j94 family 22.2.1 operation as a state machine the a/d conversion process can be thought of in terms of a finite state machine ( figure 22-3 ). the sample state represents the time that the input channel is connected to the s/h amplifier and the signal is passed to the converter input. the convert state is transitory. the module enters this state as soon as it exits the sample state and transitions to a different state when that is done. the inactive state is the default state prior to module initialization and following a software-con- trolled conversion; it can be avoided in operation by using auto-sample mode. machine states are identi- fied by the state of several control and status bits in adcon1h/l. if the module is configured for auto-sample mode, the operation ?ping-pongs? continuously between the sample and convert states. the module automatically selects the input channels to be sampled (if channel scanning is enabled), while the selected conversion trigger source paces the entire operation. any time that auto-sample mode is not used for conversion, it is available for the sample state. the user needs to make certain that acquisition time is sufficient, in addition to accounting for the normal concerns about system throughput. whenever the issue of sampling time is important, the significant event is the transition from sample to con- vert state. this is the point where the sample-and-hold aperture closes, and it is essentially the signal value at this instant, which is applied to the a/d for conversion to digital. figure 22-3: a/d module state machine model inactive sample convert samp = 0 done = 1 samp = 0 done = 0 samp = 1 done = x samp 0 1 asam = 1 and done 0 1 asam = 0 and ssrcx trigger events done 0 1 device reset legend: hw = automatic hardware event; sw = software controlled event. note: see register 22-5 for definitions of the asam, samp, done and ssrc<3:0> bits. sw hw hw asam 0 1 or
pic18f97j94 family ds30575a-page 458 ? 2012 microchip technology inc. 22.3 a/d module configuration all of the registers described in the previous section must be configured for module operation to be fully defined. an effective approach is first, to describe the signals and sequences for the particular application. typically, it is an iterative process to assign signals to port pins, to establish timing methods and to organize a scanning scheme, as well as to integrate the whole process with the software design. the various configuration and control functions of the module are distributed throughout the module's six control registers. control functions can be broadly sorted into four groups: input, timing, conversion and output. table 22-1 shows the register location of control or status bits by register. table 22-1: a/d module functions by registers and bits the following steps should be followed for performing an a/d conversion: 1. configure the a/d module: - select the output resolution (if configurable) - select the voltage reference source to match the expected range on analog inputs - select the analog conversion clock to match the desired data rate with a processor clock - determine how sampling will occur - set the multiplexer input assignments - select the desired sample/conversion sequence - select the output data format - select the output value destination - select the number of readings per interrupt 2. configure the a/d interrupt (if required): - clear the adif bit - select the a/d interrupt priority 3. turn on the a/d module. the options for each configuration step are described in the subsequent sections. 22.3.1 selecting the resolution the mode12 bit (adcon1h<3>) controls output resolution. setting this bit selects 12-bit resolution. 22.3.2 selecting the voltage reference source the voltage references for a/d conversions are selected using the pvcfg<1:0> and nvcfg0 control bits (adcon2h<7:5>). the upper voltage reference (vr+) may be av dd , the external v ref + or an internal band gap reference voltage. the lower voltage reference (vr-) may be av ss or the v ref - input pin. the available options vary between device families. the external voltage reference pins may be shared with the an0 and an1 inputs on low pin count devices. the a/d converter can still perform conversions on these pins when they are shared with the v ref + and v ref - input pins. the voltages applied to the external reference pins must meet certain specifications. refer to the device data sheet for further details. a/d function register(s) specific bits input ad1con2 pvcfg<1:0>, nv cfg, offcal, cscna, alts ad1con5 ctmreq, bgreq, vrsreq ad1chs ch0nb<2:0>, ch0sb<4:0>, ch0na<2:0>, ch0sa<4:0> ad1cssh/l css<31:16>, css<15:0> ( 1 ) ad1ctmenh/l ctmen<31:16>, ctmen<15:0> ( 1 ) conversion ad1con1 adon, adsidl, ssrc<3:0>, asam, samp, done ad1con2 smpi<4:0> ad1con3 extsam ad1con5 asen, lpen, asint<1:0> timing ad1con3 adrc, samc<4:0>, adcs<7:0> output ad1con1 form<1:0>, dmaen, dmabm ad1con2 bufs, bufm, bufregen ad1con4 dmabl<2:0> ad1con5 wm<1:0>, cm<1:0> note: do not write to the ssrcx, bufs, smpix, bufm and alts bits, or the ad1con3 and ad1cssl registers, while adon = 1 ; otherwise, indeterminate conversion data may result.
? 2012 microchip technology inc. ds30575a-page 459 pic18f97j94 family 22.3.3 selecting the a/d conversion clock the a/d converter has a maximum rate at which conversions may be completed. an analog module clock, tad, controls the conversion timing. the a/d conversion requires 14 clock periods (14 tad) for a 12-bit conversion and 12 clock periods (12 tad) for a 10-bit conversion. the a/d clock is derived from the device instruction clock. the period of the a/d conversion clock is software selected using a 6-bit counter. there are 64 possible options for tad, specified by the adcsx bits in the adcon3l register. equation 22-1 gives the tad value as a function of the adcsx control bits and the device instruction cycle clock period, tcy. for correct a/d conversions, the a/d conversion clock (tad) must be selected to ensure a minimum tad time, as specified by the device family data sheet. equation 22-1: a/d conversion clock period the a/d converter also has its own dedicated rc clock source that can be used to perform conversions. the a/d rc clock source should be used when conversions are performed while the device is in sleep mode. the rc oscillator is selected by setting the adrc bit (adcon3h<7>). when the adrc bit is set, the adcsx bits have no effect on a/d operation. 22.3.4 configuring analog port pins the a/d module does not have an internal provision to configure port pins for analog operation. instead, input pins are configured as analog inputs through the analog select registers (ansn, where ?n? is the port name). a pin is configured as an analog input when the corresponding ansn bit is set. by default, pins with multiplexed analog and digital functions are configured as analog pins on device reset. for external analog inputs, both the ansn register and the corresponding tris register bits control the opera- tion of the a/d port pins. the port pins that will function as analog inputs must also have their corresponding tris bits set, specifying the pins as inputs. after a device reset, all tris bits are set. if the i/o pin asso- ciated with an a/d channel is configured as a digital output (tris bit is cleared), while the pin is configured for analog mode, the port digital output level (voh or vol) will be converted. 22.3.5 input channel selection the a/d converter incorporates two independent sets of input multiplexers (mux a and mux b) that allow users to choose which analog channels are to be sam- pled. the inputs specified by the ch0sax and ch0nax bits are collectively called the mux a inputs. the inputs specified by the ch0sbx and ch0nbx bits are collec- tively called the mux b inputs. functionally, mux a and mux b are very similar to each other. both multiplexers allow any of the analog input channels to be selected for individual sampling and allow selection of a negative reference source for differ- ential signals. in addition, mux a can be configured for sequential analog channel scanning. this is discussed in more detail in section 22.3.5.1 ?configuring mux a and mux b inputs? and section 22.3.5.3 ?scanning through several inputs? . 22.3.5.1 configuring mux a and mux b inputs the user may select any one of up to 32 inputs avail- able to the a/d converter as the positive input of the s/h amplifier. for mux a, the ch0sa<4:0> bits (adchs0l<4:0>) normally select the analog channel for the positive input. for mux b, the positive channel is selected by the ch0sb<4:0> bits (adchs0h<4:0>). all of the external analog channels are available as positive inputs. in addition to the external inputs, these may also include device supply voltage (av dd ), the logic core supply voltage (v ddcore ), the internal band gap voltage (vbg) and/or multiples or fractions of vbg. one or more additional input channels are used for the ctmu. these selections leave the a/d disconnected from all other inputs. the options vary by device family; refer to the specific device data sheet for details. t cy (adcsx + 1) adcs x =? 1 t ad t cy note: based on t cy = 2/f osc ; doze mode t ad = and pll are disabled. note 1: when reading a port register, any pin configured as an analog input reads as ? 0 ?. 2: analog levels on any pin that is defined as a digital input may cause the input buffer to consume current that is out of the device?s specification. note: different pic18f devices will have different numbers of analog inputs. verify the analog input availability against the particular device?s data sheet.
pic18f97j94 family ds30575a-page 460 ? 2012 microchip technology inc. the ctmu input is selected by the adctmuen1h/l, adctmuen0h/l registers. setting a particular bit in one of these registers effectively assigns the analog output from the ctmu to the corresponding a/d input channel, automatically enabling the ctmu. many devices will already have a ch0sax bit combination designated for use of the ctmu. this setting discon- nects the converter from any other load. this channel should be the one selected by the appropriate adctmuen bit. if another channel is selected, verify that any other analog sources are disconnected from that channel; otherwise, erroneous readings may result. for the negative (inverting) input of the amplifier, the user has up to eight options, selected by the ch0na<2:0> and ch0nb<2:0> bits (adchs0l<7:5> and adchs0h<7:5>, respectively). options typically include the device ground (av ss ), the current vr- source designated by the nvcfg0 bit (adcon2h<5>), and one or more of the external analog input channels. as with the non-inverting inputs, the options vary by device family. 22.3.5.2 alternating mux a and mux b input selections by default, the a/d converter only samples and con- verts the inputs selected by mux a. the alts bit (adcon2l<0>) enables the module to alternate between two sets of inputs selected by mux a and mux b during successive samples. if the alts bit is ' 0 ', only the inputs specified by the ch0sax and ch0nax bits are selected for sampling. when the alts bit is ' 1 ', the module will alternate between the mux a inputs on one sample and the mux b inputs on the subsequent sample. if the alts bit is ' 1 ' on the first sample/convert sequence, the inputs specified by the ch0sax and ch0nax bits are selected for sampling. on the next sample/convert sequence, the inputs specified by the ch0sbx and ch0nbx bits are selected for sampling. this pattern repeats for subsequent sample conversion sequences. 22.3.5.3 scanning through several inputs when using mux a to select analog inputs, the a/d module has the ability to scan multiple analog chan- nels. when the cscna bit (adcon2h<>) is set, the ch0sa bits are ignored and the channels specified by the adcss1h/l, adcss0h/l registers are sequen- tially sampled. each bit in the adcss1h/l registers and adcss0h/l registers (when implemented) corresponds to one of the analog channels. if a bit in the adcss0h/l or adcss1h/l registers is set, the corresponding analog channel is included in the scan sequence. inputs are always scanned from lower to higher numbered inputs, starting at the first selected channel after each interrupt occurs. the adcss1h/l, adcss0h/l registers' bits specify the positive input of the channel. the ch0nax bits still select the negative input of the channel during scanning. scanning is only available on the mux a input selection. the mux b input selection, as specified by the ch0sbx bits, will still select the alternating input. when alternated sampling between mux a and mux b is selected (alts = 1 ), the input will alternate between a set of scanning inputs specified by the adcss1h/l, adcss0h/l registers, and a fixed input specified by the ch0sbx bits. automatic scanning can be used in conjunction with the threshold detect feature to determine if one or more analog channels meet a predetermined set of condi- tions while the cpu is inactive. this is described in detail in section 22.7 ?threshold detect operation? . 22.3.5.4 internal channels in low-power modes while the a/d module can scan and convert analog inputs in low-power modes, some internal analog inputs may be unavailable in sleep mode. the main examples are the ctmu module, the internal band gap voltage source and the on-chip voltage regulator (for those devices that include one). the a/d module provides a method to make these resources available automatically through the ctmureq bit (adcon5h<5>). setting one or more of these bits causes the corresponding internal analog source(s) to become active during a channel scan. 22.3.6 enabling the module when the adon bit (adcon1h<7>) is set, the module is fully powered and functional. when adon is ' 0 ', the module is disabled. although the digital and analog portions of the circuit are turned off for maximum current savings, the contents of all registers are maintained. note 1: if the number of scanned inputs selected is greater than the number of samples taken per interrupt, the higher numbered inputs will not be sampled. 2: if the ctmu channel is to be included in a scan operation, verify that the proper analog input channel is selected and that the ad1ctmen register(s) are correctly configured. for more information, see section 22.3.5.1 ?configuring mux a and mux b inputs? .
? 2012 microchip technology inc. ds30575a-page 461 pic18f97j94 family conversion data stored in the adcbuf registers will also be maintained, including any threshold values stored by the user. it may be necessary to re-initialize these registers to their proper values before re-enabling the module. when enabling the module by setting the adon bit, the user must wait for the analog stages to stabilize. for the stabilization time, refer to section 31.0 ?electrical characteristics? . 22.4 controlling the sampling process 22.4.1 manual sampling setting the samp bit (adcon1l<1>) while the asam bit (adcon1l<2>) is clear causes the a/d to begin sampling. clearing the samp bit ends sampling and automatically begins the conversion; however, there must be a sufficient delay between setting and clearing samp for the sampling process to start. sampling will not resume until the samp bit is once again set. for an example, see figure 22-4 . 22.4.2 automatic sampling setting the asam bit causes the a/d to automatically begin sampling after a conversion has been completed. one of several options can be used as an event to end sampling and complete the conversions. sampling will continue on the next selected channel after the conver- sion in progress has completed. for an example, see figure 22-5 . 22.4.3 monitoring sample status the samp bit indicates the sampling state of the a/d. generally, when the samp bit clears, indicating the end of sampling, the done bit is automatically cleared to indicate the start of conversion. if samp is ' 0 ' while done is ' 1 ', the a/d is in an inactive state. 22.4.4 aborting a sample while in manual sampling mode, clearing the samp bit will terminate sampling. if ssrc<3:0> = 0000 , it may also start a conversion automatically. clearing the asam bit while in automatic sampling mode will not terminate an ongoing sample/convert sequence; however, sampling will not automatically resume after a subsequent conversion. 22.5 controlling the conversion process the conversion trigger source will terminate sampling and start a selected sequence of conversions. the ssrc<3:0> bits (adcon1l<7:4>) select the source of the conversion trigger. 22.5.1 manual control when ssrc<3:0> = 0000 , the conversion trigger is under software control. clearing the samp bit (adcon1l<1>) starts the conversion sequence. figure 22-4 is an example where setting the samp bit initiates sampling, and clearing the samp bit terminates sampling and starts conversion. the user software must time the setting and clearing of the samp bit to ensure adequate sampling time of the input signal. figure 22-5 is an example where setting the asam bit initiates automatic sampling, and clearing the samp bit terminates sampling and starts conversion. after the conversion completes, the module sets the samp bit and returns to the sample state. the user software must time the clearing of the samp bit to ensure adequate sampling time of the input signal, under- standing that the time since previously clearing the samp bit includes the conversion time, which immedi- ately follows, as well as the next sampling time. note 1: the available conversion trigger sources may vary depending on the pic18f device variant. refer to the specific device data sheet for the available conversion trigger sources. 2: the ssrcx selection bits should not be changed when the a/d module is enabled. if the user wishes to change the conversion trigger source, disable the a/d module first by clearing the adon bit (ad1con1<15>).
pic18f97j94 family ds30575a-page 462 ? 2012 microchip technology inc. figure 22-4: converting one chann el, manual sample start, manual conversion start example 22-1: converting one channel , manual sample start, manual conversion start code figure 22-5: converting one channel , automatic sample start, manual conversion start a/d clk samp adc1buf0 t samp t conv bcf ad1con1, samp bsf ad1con1, samp instruction execution done int adcvalue; ansb = 0x0001; // an2 as analog, all other pins are digital ad1con1 = 0x0000; // samp bit = 0 ends sampling and starts converting ad1chs = 0x0002; // connect an2 as s/h+ input // in this example an2 is the input ad1cssl = 0; ad1con3 = 0x0002; // manual sample, tad = 3tcy ad1con2 = 0; ad1con1bits.adon = 1; // turn adc on while (1) // repeat continuously { ad1con1bits.samp = 1; // start sampling... delay(); // ensure the correct sampling time has elapsed // before starting conversion. ad1con1bits.samp = 0; // start converting while (!ad1con1bits.done){}; // conversion done? adcvalue = adc1buf0; // yes then get adc value } a/d clk samp adc1buf0 t samp t conv bcf ad1con1, samp t conv bsf ad1con1, asam bcf ad1con1, samp t samp t ad 0 t ad 0 instruction execution
? 2012 microchip technology inc. ds30575a-page 463 pic18f97j94 family 22.5.2 clocked conversion trigger when adrc = 1 , the conversion trigger is under a/d clock control. the samcx bits (adcon3h<4:0>) select the number of tad clock cycles between the start of sampling and the start of conversion. after the start of sampling, the module will count a number of tad clocks specified by the samcx bits. the samcx bits must always be programmed for at least one clock cycle to ensure sampling requirements are met. equation 22-2: clocked conversion trigger time figure 22-6 shows how to use the clocked conversion trigger with the sampling started by the user software. figure 22-6: converting one chann el, manual sample start, t ad -based conversion start example 22-2: converting one chann el, manual sample start, t ad -based conversion start code t smp = samc<4:0> * t ad a/d clk samp adc1buf0 t samp t conv bsf ad1con1, samp instruction execution done int adcvalue; ansb = 0x1000; // all portb = digital; rb12 = analog ad1con1 = 0x00e0; // ssrc<2:0> = 111 implies internal counter ends sampling // and starts converting. ad1chs = 0x000c; // connect an12 as s/h input. // in this example an12 is the input ad1cssl = 0; ad1con3 = 0x1f02; // sample time = 31tad, tad = 3tcy ad1con2 = 0; ad1con1bits.adon = 1; // turn adc on while (1) // repeat continuously { ad1con1bits.samp = 1; // start sampling, then after 31tad go to conversion while (!ad1con1bits.done){}; // conversion done? adcvalue = adc1buf0; // yes then get adc value } // repeat
pic18f97j94 family ds30575a-page 464 ? 2012 microchip technology inc. 22.5.2.1 free-running sample conversion sequence using the auto-convert conversion trigger mode (ssrc<3:0> = 0111 ), in combination with the auto-sample start mode (asam = 1 ), allows the a/d module to schedule sample/conversion sequences with no intervention by the user or other device resources. this ?clocked? mode, shown in figure 22-7 , allows continuous data collection after module initial- ization. note that all timing in this mode scales with tad, either from the a/d internal rc clock or from tcy (as prescaled by the adcs<7:0> bits). in both cases, the samc<4:0> bits set the number of tad clocks in tsamp. tconv is fixed at 12 tad. figure 22-7: converting one channel, auto-sample start, t ad -based conversion start 22.5.2.2 sample time considerations using clocked conversion trigger and automatic sampling the user must ensure the sampling time satisfies the sampling requirements, as outlined in section 22.9 ?a/d sampling requirements? . assuming that the module is set for automatic sampling and using a clocked conversion trigger, the sampling interval is specified by the samcx bits. 22.5.3 event trigger conversion start it is often desirable to synchronize the end of sampling and the start of conversion with some other time event. depending on the device family, the a/d module has up to 16 sources available to use as a conversion trigger event. the event trigger is selected by the ssrc<3:0> bits (adcon1l<7:4>). as noted, the available event triggers vary between device families. refer to the specific device data sheet for specific information. the examples that follow represent trigger sources that are implemented in most devices. note that the ssrcx bit assignments may vary in some devices. 22.5.3.1 external int0 pin trigger when ssrc<3:0> = 0001 , the a/d conversion is triggered by an active transition on the int0 pin. the pin may be programmed for either a rising edge input or a falling edge input. 22.5.3.2 special event trigger when ssrc<3:0> = 0010 , the a/d is triggered by a special event trigger. refer to ccp and eccp section for more information about special event triggers. 22.5.3.3 synchronizing a/d operations to internal or external events the modes where an external event trigger pulse ends sampling and starts conversion may be used in combi- nation with auto-sampling (asam = 1 ) to cause the a/d to synchronize the sample conversion events to the trigger pulse source. for example, in figure 22-9 , where ssrc<3:0> = 0010 and asam = 1 , the a/d will always end sampling and start conversions synchro- nously with the timer compare trigger event. the a/d will have a sample conversion rate that corresponds to the timer comparison event rate. a/d clk samp adc1buf1 t samp t conv done t samp t conv adc1buf0 bsf ad1con1, asam instruction execution reset by software
? 2012 microchip technology inc. ds30575a-page 465 pic18f97j94 family 22.5.3.4 sample time considerations for automatic sampling/conversion sequences different sample/conversion sequences provide differ- ent available sampling times for the s/h channel to acquire the analog signal. the user must ensure the sampling time satisfies the sampling requirements, as outlined in section 22.9 ?a/d sampling require- ments? . assuming that the module is set for automatic sam- pling, and an external trigger pulse is used as the con- version trigger, the sampling interval is a portion of the trigger pulse interval. the sampling time is the trigger pulse period, less the time required to complete the conversion. equation 22-3: calculating available sa mpling time for sequential sampling figure 22-8: manual sample start, co nversion trigger-based conversion start figure 22-9: auto-sample st art, conversion trigger-based conversion start t smp = trigger pulse interval (t seq ) ? conversion time (t conv ) = t seq ? t conv conversion trigger a/d clk samp adc1buf0 t samp t conv bsf ad1con1, samp instruction execution conversion trigger a/d clk samp adc1buf0 t samp t conv bsf ad1con1, asam t conv t samp adc1buf1 done reset by software instruction execution
pic18f97j94 family ds30575a-page 466 ? 2012 microchip technology inc. 22.5.4 monitoring sample/conversion status the done bit (adcon1l<0>) indicates the conver- sion state of the a/d. generally, when the samp bit clears, indicating the end of sampling, the done bit is automatically cleared to indicate the start of conver- sion. if samp is ' 0 ' while done is ' 1 ', the a/d is in an inactive state. in some operational modes, the samp bit may also invoke and terminate sampling. in these modes, the done bit cannot be used to terminate conversions in progress. 22.5.5 generating a/d interrupts the smpi<4:0> bits (adcon2l<6:2>) control the generation of the a/d interrupt flag, adif. the a/d interrupt flag is set after the number of sample/conver- sion sequences is specified by the smpix bits, after the start of sampling, and continues to recur after that number of samples. the value specified by the smpix bits also corresponds to the number of data samples in the buffer, up to the maximum of 16. to enable the interrupt, it is necessary to set the a/d interrupt enable bit, adie. if auto-scan is enabled (adcon5<7> = 1 ), interrupt generation is controlled by the asintmdx bits (adcon5h<1:0>). for more information, refer to section 22.7.4 ?threshold detect interrupts? . 22.5.6 aborting a conversion clearing the adon bit during a conversion will abort the current conversion. the a/d results buffer will not be updated with the partially completed a/d conversion sample; that is, the corresponding adcbuf buffer location will continue to contain the value of the last completed conversion (or the last value written to the buffer). 22.5.7 offset calibration the module provides a simple calibration method to offset the effects of internal device noise. while not always necessary, this may be helpful in situations where weak analog signals are being converted. calibration is performed by using the offcal bit (adcon2h<4>). this disconnects the s/h amplifier entirely from any inputs. with the offcal bit set, a single reference conversion is performed. the results of this conversion are value added by internal device noise. this result can be stored by the application, then used as an offset value for future conversions. 22.6 a/d results buffer as conversions are completed, the module writes the results of the conversions into the a/d result buffer. this buffer is a ram array of fixed word size, accessed through the sfr space. the size of the buffer is deter- mined by the number of external analog input channels on the device, allowing one word for each channel. depending on the device, additional buffer space may be provided for one or more internal analog channels (e.g., band gap sources). the number of buffer addresses is always even and always at least equal to the number of external channels. user software may attempt to read each a/d conver- sion result as it is generated; however, this might consume too much cpu time. generally, to minimize software overhead, the module will fill the buffer with results and then generate an interrupt when the buffer is filled. 22.6.1 number of conversions per interrupt the smpi<4:0> bits select how many a/d conversions will take place before the cpu is interrupted. this can vary from 1 to 16 samples per interrupt. the a/d converter module always starts writing its conversion results at the beginning of the buffer, after each interrupt. for example, if smpi<4:0> = 00000 , the conversion results will always be written to the adcbuf0. in this example, no other buffer locations would be used, since only one sequence per interrupt is specified. 22.6.2 buffer fill modes the results buffer can be configured to operate in either of two modes: a standard fifo mode, compatible with the earlier 10-bit a/d module (default), or a channel indexed mode. the fill mode is selected by the bufregen bit (adcon2h<3>). 22.6.2.1 fifo modes when bufregen = 0 , the results buffer operates in fifo mode. the first conversion results, after initiating conversions, is written to the first available buffer address. subsequent conversions are written to the next sequential buffer location, continuing until the process is interrupted. if allowed to continue without interrupts, the module would fill each location and then wrap around to the first address, continuing the process. note: this section describes buffer operation in legacy mode (ad1con5<3:2> = 00 ). buffer operation is different when the compare only or compare and save modes are used with the threshold detect feature. for more information, see section 22.7 ?threshold detect operation? .
? 2012 microchip technology inc. ds30575a-page 467 pic18f97j94 family the bufm bit (adcon2l<1>) controls how the buffer is filled. when bufm is ' 1 ', the buffer is split into two equal halves: a lower half (adcbuf0 through adcbuf[(n/2) - 1]) and an upper half (adcbuf[n/2] through adcbufn), where n is the number of available analog channels (both internal and external). the buffers will alternately receive the conversion results after each interrupt event. the initial buffer used after bufm is set is the lower group. when bufm is ' 0 ', the entire buffer is used for all conversion sequences. the decision to use the split buffer feature will depend upon how much time is available to move the buffer contents after the interrupt, as determined by the application. if the application can quickly unload a full buffer within the time it takes to sample and convert one channel, the bufm bit can be ' 0 ', and up to 16 conver- sions may be done per interrupt. the application will have one sample/convert time before the first buffer location is overwritten. if the processor cannot unload the buffer within the sample and conversion time, the bufm bit should be ' 1 '. for example, if smpi<4:0> = 00111 , then eight conversions will be loaded into the lower half of the buffer, following which, an interrupt may occur. the next eight conversions will be loaded into the upper half of the buffer. the processor will, therefore, have the entire time between interrupts to move the eight conversions out of the buffer. 22.6.2.2 buffer fill status when the conversion result buffer is split (bufm = 1 ), the bufs status bit (adcon2l<7>) indicates which half of the buffer that the a/d converter is currently writ- ing. if bufs = 0 , the a/d converter is filling the lower group and the user application should read conversion values from the upper group. if bufs = 1 , the situation is reversed, and the user application should read conversion values from the lower group. 22.6.2.3 channel indexed mode when bufregen = 1 , fifo operation is disabled. in this fill mode, the conversion result for each channel is written only to the buffer location that corresponds to that channel. for example, any conversions performed on an0 are stored only in adcbuf0. the same holds true for an1 and adcbuf1, and so on. subsequent conversions on a particular channel that occur, prior to an interrupt, will result in any previous data in that location being overwritten. channel indexed mode is particularly useful when used with the threshold detect feature, as this allows the user to easily test for a particular condition on a specific analog channel without creating an excess of cpu overhead. this is covered in more detail in section 22.7 ?threshold detect operation? . 22.6.3 buffer data formats the results of each a/d conversion are 12 bits wide (optionally, 10 bits wide in some devices). to maintain data format compatibility, the result of each conversion is automatically converted to one of four selectable, 16-bit formats. the form<1:0> bits (adcon1h<1:0>) select the format. figure 22-10 and figure 22-11 show the data output formats that can be selected. table 22-2 through table 22-5 show the numerical equivalents for the various conversion result codes. figure 22-10: a/d output data formats (12-bit) note: when the bufm bit is set, the user should not program the smpix bits to a value that specifies more than (n/2) conversions per interrupt. ram contents: d11 d10 d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 read to bus: integer 0000d11d10d09d08d07d06d05d04d03d02d01d00 signed integer d11 d11 d11 d11 d11 d10 d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 fractional (1.15) d11 d10 d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 0 0 0 0 signed fractional (1.15) d11 d10 d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 0 0 0 0
pic18f97j94 family ds30575a-page 468 ? 2012 microchip technology inc. table 22-2: numerical equivalents of various result codes: 12-bit integer formats table 22-3: numerical equivalents of v arious result codes: 12-bit fractional formats figure 22-11: a/d output data formats (10-bit) v in /v ref 12-bit output code 16-bit integer format/ equivalent decimal value 16-bit signed integer format/ equivalent decimal value 4095/4096 1111 1111 1111 0000 1111 1111 1111 4095 0000 0111 1111 1111 2047 4094/4096 1111 1111 1110 0000 1111 1111 1110 4094 0000 0111 1111 1110 2046 ??? 2049/4096 1000 0000 0001 0000 1000 0000 0001 2049 0000 0000 0000 0001 1 2048/4096 1000 0000 0000 0000 1000 0000 0000 2048 0000 0000 0000 0000 0 2047/4096 0111 1111 1111 0000 0111 1111 1111 2047 1111 1111 1111 1111 -1 ??? 1/4096 0000 0000 0001 0000 0000 0000 0001 1 1111 1000 0000 0001 -2047 0/4096 0000 0000 0000 0000 0000 0000 0000 0 1111 1000 0000 0000 -2048 v in /v ref 12-bit output code 16-bit fractional format/ equivalent decimal value 16-bit signed fractional format/ equivalent decimal value 4095/4096 1111 1111 1111 1111 1111 1111 0000 0.999 0111 1111 1111 0000 0.499 4094/4096 1111 1111 1110 1111 1111 1110 0000 0.998 0111 1111 1110 0000 0.498 ??? 2049/4096 1000 0000 0001 1000 0000 0001 0000 0.501 0000 0000 0001 0000 0.001 2048/4096 1000 0000 0000 1000 0000 0000 0000 0.500 0000 0000 0000 0000 0.000 2047/4096 0111 1111 1111 0111 1111 1111 0000 0.499 1111 1111 1111 0000 -0.001 ??? 1/4096 0000 0000 0001 0000 0000 0001 0000 0.001 1000 0000 0001 0000 -0.499 0/4096 0000 0000 0000 0000 0000 0000 0000 0.000 1000 0000 0000 0000 -0.500 ram contents: d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 read to bus: integer 000000 d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 signed integer d09 d09 d09 d09 d09 d09 d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 fractional (1.15) d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 000000 signed fractional (1.15) d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 000000
? 2012 microchip technology inc. ds30575a-page 469 pic18f97j94 family table 22-4: numerical equivalents of various result codes: 10-bit integer formats table 22-5: numerical equivalents of v arious result codes: 10-bit fractional formats 22.7 threshold detect operation threshold detect is a significant extension of the auto-scan feature offered in previous 10-bit a/d mod- ules. in addition to being able to repeatedly sample a predefined sequence of analog channels, threshold detect allows the user to define match conditions based on the conversion results and generate an inter- rupt based on these conditions. during normal opera- tion, this can potentially reduce the amount of cpu time spent on processing a/d interrupts. for low-power applications, this can allow the cpu to remain inactive for longer periods, waking only when specific analog conditions are met. when selected by the user, threshold detect changes the operation of the a/d results buffer by making it a read/write array for both conversion results and com- parison (threshold) values. it also brings into play the ad1chit registers, which are used to indicate match conditions. independently selectable comparison and buffer storage settings make a wide range of operating combinations possible. 22.7.1 operating modes the operation of threshold detect is mostly controlled by the adcon5h/l registers. the asena bit (adcon5l<7>) controls overall operation of threshold detect; setting this bit enables the functionality. as with legacy auto-scan operation, the channels to be included are selected using the adcss1h/l, adcss0h/l registers. setting a particular bit in either register includes the corresponding channel in an automatic sequential scan. one or more channels may be selected. after the channels have been selected, setting both the cscna and asena bits to enable a single scan of the designated channels. the scan itself is triggered by the trigger source programmed by the ssrc<3:0> bits. . v in /v ref 10-bit output code 16-bit integer format/ equivalent decimal value 16-bit signed integer format/ equivalent decimal value 1023/1024 11 1111 1111 0000 0011 1111 1111 1023 0000 0001 1111 1111 511 1022/1024 11 1111 1110 0000 0011 1111 1110 1022 0000 0001 1111 1110 510 ??? 513/1024 10 0000 0001 0000 0010 0000 0001 513 0000 0000 0000 0001 1 512/1024 10 0000 0000 0000 0010 0000 0000 512 0000 0000 0000 0000 0 511/1024 01 1111 1111 0000 0001 1111 1111 511 1111 1111 1111 1111 -1 ??? 1/1024 00 0000 0001 0000 0000 0000 0001 1 1111 1110 0000 0001 -511 0/1024 00 0000 0000 0000 0000 0000 0000 0 1111 1110 0000 0000 -512 v in /v ref 10-bit output code 16-bit fractional format/ equivalent decimal value 16-bit signed fractional format/ equivalent decimal value 1023/1024 11 1111 1111 1111 1111 1100 0000 0.999 0111 1111 1100 0000 0.499 1022/1024 11 1111 1110 1111 1111 1000 0000 0.998 0111 1111 1000 0000 0.498 ??? 513/1024 10 0000 0001 1000 0000 0100 0000 0.501 0000 0000 0100 0000 0.001 512/1024 10 0000 0000 1000 0000 0000 0000 0.500 0000 0000 0000 0000 0.000 511/1024 01 1111 1111 0111 1111 1100 0000 0.499 1111 1111 1100 0000 -0.001 ??? 1/1024 00 0000 0001 0000 0000 0100 0000 0.001 1000 0000 0100 0000 -0.499 0/1024 00 0000 0000 0000 0000 0000 0000 0.000 1000 0000 0000 0000 -0.500 note: legacy auto-scan (i.e., sequential scanning of analog channels on mux a, without any comparison) is controlled by the cscna bit (ad1con2<10>) and does not depend on the asen bit to function
pic18f97j94 family ds30575a-page 470 ? 2012 microchip technology inc. the lpena bit (adcon5h<6>) allows threshold detect to function with a low-power feature. by design, threshold detect can perform comparison operations when the device is in sleep or idle modes, waking the cpu when it generates an interrupt. setting lpena configures the device to return to low-power operation after the interrupt has been serviced. the compare mode bits, cm<1:0> (adcon5l<1:0>), select the type of comparison to be performed. four types are available: ? the result of the current conversion is greater than a reference threshold ? the result of the current conversion is less than a reference threshold ? the result of the current conversion is between two predefined thresholds (?inside window?) ? the result of the current conversion is outside of the predefined thresholds (?outside window?) the write mode bits, wm<1:0> (adcon5l<3:2>), determine the disposition of the conversion. three options are available: ? discard the conversion after the comparison has been performed ? store the conversion after the comparison has been performed ? store the conversion without comparison (legacy mode) 22.7.1.1 buffer operation and comparisons for buffer write modes that involve storing conver- sions (wm<1:0> = 0x ), the bufm and bufregen bits control how the buffer functions (as a channel indexed, single fifo or split fifo buffer). however, when the compare and store option is selected (wm<1:0> = 01 ), using a fifo mode may overwrite the buffers of other channels and cause unpredictable comparison results. for that reason, always use channel indexed buffer mode (bufregen = 1 ) when using the compare and store option. 22.7.1.2 buffer operation in windowed comparisons (channel mirroring) the use of windowed comparisons changes the avail- able options for the results buffer. to accommodate the storage of two threshold values, the buffer is automati- cally split into halves, similar to split fifo mode. buffer addresses in each half are paired, with the lowest address in one buffer, matched to the buffer address in the upper half. (for example, in a 16-word buffer, adcbuf0 is paired with adcbuf9, adcbuf1 is paired with adcbuf10, and so on.) this pairing is referred to as ?channel mirroring?. mirroring can obviously be applied only to the lower a/d channels; for most devices, this corresponds to the lower half of the external analog channels. this does not mean that those buffer locations cannot be used for other purposes. however, storing any other data in a particular buffer location, where channel mirroring is being used, may result in misleading comparison evaluations. 22.7.2 setting comparison thresholds the comparison thresholds for threshold detect are set by writing the desired values to an appropriate location in the a/d results buffer. this can only be done when the module is deactivated (adcon1h<7> = 0 ). the location of the threshold is determined by the comparison type. for simple greater than, and less than, comparisons, the value is written to the buffer location corresponding to the input channel to be monitored. for example, if an0 is to be monitored for a voltage over a certain level, the ceiling threshold is stored in adcbuf0. the location of the thresholds for windowed compari- sons are written to two addresses. the lower value is written to the address corresponding to the monitored channel. the upper value is stored in the correspond- ing mirrored address in the upper half of the buffer. to expand on the previous example, if the conversion on an0 is to be a windowed comparison, the floor thresh- old is stored in adcbuf0, while the ceiling threshold is stored in adcbuf9. 22.7.3 compare hit registers to determine if a particular event has occurred, the a/d module uses two registers to record match events. these registers are referred to as the compare hit registers and are designated, adchit1h/l and adchit0h/l. the registers map their individual bits sequentially to each of the (up to) 32 analog channels. if a particular channel in a device is not implemented, the corresponding compare hit bit (chhn) is not implemented. each bit serves as an event semaphore for its corre- sponding channel. when the programmed event occurs on that channel, the bit becomes set and stays set until it is cleared by the application. it is the user's responsibility to clear the bits after the application has evaluated them. depending on the event, more than one compare hit bit may be set. the significance of a set bit must be inter- preted by the application in the context of the compare mode selected. particular examples are covered in section 22.7.5 ?comparison mode examples? .
? 2012 microchip technology inc. ds30575a-page 471 pic18f97j94 family 22.7.4 threshold detect interrupts the a/d module can generate an interrupt and set the adif flag based on threshold detect operation. this is based on completion of a threshold detect sequence and/or the occurrence of a valid compari- son. when threshold detect is enabled (asena = 1 ), a/d module interrupt generation is governed by the asintmdx bits (adcon5h<1:0>), superseding any configuration implemented by the smpix bits (adcon2l<6:2>). for information on alternative interrupt settings, refer to section 22.6.1 ?number of conversions per interrupt? . the threshold detect interrupt is configured by the asintmd<1:0> bits (adcon5h<1:0>). options include interrupt after a scan sequence, interrupt after a scan sequence with a valid match, interrupt after a valid match (without waiting for the sequence to end) or no interrupt. 22.7.5 comparison mode examples the following examples show the effect of valid comparisons on the results buffer and the compare hit registers. in each figure, changes within the registers are indicated in bold. for the sake of simplicity, the examples assume a device with only 16 analog inputs. devices with a greater number of channels, and thus, larger results buffers and two compare hit registers, will function in a similar fashion. 22.7.5.1 simple comparisons (greater and less than results) when the compare mode bits, cm<1:0> (adcon5l<1:0>), are programmed as ' 0x ', the converter compares the sampled value to see if it is greater than (cm<1:0> = 01 ), or less than (cm<1:0> = 00 ), the threshold value in the buffer location. if the condition is met, both of the following occur: ? the compare hit bit (chhn) for the correspond- ing channel is set. ? if the write mode bits, wm<1:0> (adcon5l<3:2>), are programmed to ' 01 ', the converted value is written to the buffer, replacing the threshold value. if wm<1:0> = 10 , the converted value is discarded. the changes to the result buffer and the compare hit register are shown in figure 22-13 . note that they are the same for both types of simple comparison. note: when using any comparison mode, always use channel indexed buffer storage (bufregen = 1 ). otherwise, the threshold values for other channels may be overwritten, resulting in unpredictable comparisons.
pic18f97j94 family ds30575a-page 472 ? 2012 microchip technology inc. figure 22-12: simple comparison operat ions (greater than and less than) 22.7.5.2 inside window comparison when the compare mode bits, cm<1:0>, are programmed as ' 10 ', the converter compares the sam- pled value to see if it falls between the threshold values in the buffer and mirrored channel location. since the value in the mirrored channel location is always the greater value of the two thresholds, the condition is met when: threshold 2 > converted value > threshold 1 in this case, both of the following occur: ? the compare hit bit (chhn) for the correspond- ing channel is set; the compare hit bit for the mirrored channel remains cleared. ? if the write mode bits, wm<1:0> (adcon5l<3:2>), are programmed to ' 01 ', the converted value is written to the buffer, replacing the lower threshold value. if wm<1:0> = 10 , the converted value is discarded. the changes to the result buffer and the compare hit register are shown in figure 22-14 . adc1buf15 ? adc1buf14 ? adc1buf13 ? adc1buf12 ? adc1buf11 ? adc1buf10 ? adc1buf9 ? adc1buf8 ? adc1buf7 ? adc1buf6 ? adc1buf5 ? adc1buf4 ? adc1buf3 ? adc1buf2 threshold value adc1buf1 ? adc1buf0 ? before conversion and comparison ad1chitl 15 14 13 12 11 10 9 8 0000000 0 76543 2 10 00000 1 00 after conversion and comparison compare only (? 10 ?) compare and store (? 01 ?) adc1buf15 ? ? adc1buf14 ? ? adc1buf13 ? ? adc1buf12 ? ? adc1buf11 ? ? adc1buf10 ? ? adc1buf9 ? ? adc1buf8 ? ? adc1buf7 ? ? adc1buf6 ? ? adc1buf5 ? ? adc1buf4 ? ? adc1buf3 ? ? adc1buf2 threshold value conversion value adc1buf1 ? ? adc1buf0 ? ? ad1chitl 15 14 13 12 11 10 9 8 00000000 76543210 00000000
? 2012 microchip technology inc. ds30575a-page 473 pic18f97j94 family figure 22-13: inside windo w comparison operation 22.7.5.3 outside window comparison when the compare mode bits cm<1:0> are programmed as ' 11 ', the converter compares the sampled value to see if it falls outside of the threshold values in the buffer and mirrored channel location. again, since the value in the mirrored channel location is always the greater value of the two thresholds, the condition is met when either: converted value >threshold 2 or threshold 1 > converted value in these cases, the following occurs: ? the compare hit bit (chhn) for the correspond- ing channel is set. ? if the converted value is greater than threshold 2, the chhn bit for the mirrored channel is also set. if it is less than threshold 1, the mirrored channel bit remains ' 0 '. ? if the write mode bits, wm<1:0> (adcon5l<3:2>), are programmed to ' 01 ': - if the converted value is above threshold 2, the converted value is written to the mirrored channel address, replacing the upper thresh- old value. - if the converted value is below threshold 1, the converted value is written to the channel address, replacing the lower threshold value. ? if wm<1:0> = 10 , the converted value is discarded. the changes to the result buffer and the compare hit register are shown in figure 22-15 (over the upper threshold) and figure 22-16 (under the lower thresh- old). note that when a windowed comparison mode is selected and channel mirroring is enabled, nothing pre- vents a conversion from another operation from being stored in the mirrored channel location. in the previous examples of windowed operation, if an10 is included in a threshold detect operation, a conversion on an10 might be tested against the upper threshold for an2, stored in that location. this could result in the threshold value being overwritten and/or the chh10 bit being set. adc1buf15 ? adc1buf14 ? adc1buf13 ? adc1buf12 ? adc1buf11 ? adc1buf10 threshold 2 adc1buf9 ? adc1buf8 ? adc1buf7 ? adc1buf6 ? adc1buf5 ? adc1buf4 ? adc1buf3 ? adc1buf2 threshold 1 adc1buf1 ? adc1buf0 ? before conversion and comparison ad1chitl 15 14 13 12 11 10 9 8 00000000 76543 2 10 00000 1 00 after conversion and comparison compare only (? 10 ?) compare and store (? 01 ?) adc1buf15 ? ? adc1buf14 ? ? adc1buf13 ? ? adc1buf12 ? ? adc1buf11 ? ? adc1buf10 threshold 2 threshold 2 adc1buf9 ? ? adc1buf8 ? ? adc1buf7 ? ? adc1buf6 ? ? adc1buf5 ? ? adc1buf4 ? ? adc1buf3 ? ? adc1buf2 threshold 1 conversion value adc1buf1 ? ? adc1buf0 ? ? ad1chitl 15 14 13 12 11 10 9 8 00000000 76543210 00000000
pic18f97j94 family ds30575a-page 474 ? 2012 microchip technology inc. for this reason, users must always carefully consider the allocation and use of the upper analog channels (both external and internal) when using windowed compare modes. wherever possible, exclude the upper analog channels for threshold detect operations, and convert and test those channels in a separate routine. figure 22-14: outside window compar ison operation (over threshold 2) adc1buf15 ? adc1buf14 ? adc1buf13 ? adc1buf12 ? adc1buf11 ? adc1buf10 threshold 2 adc1buf9 ? adc1buf8 ? adc1buf7 ? adc1buf6 ? adc1buf5 ? adc1buf4 ? adc1buf3 ? adc1buf2 threshold 1 adc1buf1 ? adc1buf0 ? before conversion and comparison ad1chitl 15 14 13 12 11 10 98 00000 1 00 76543 2 10 00000 1 00 after conversion and comparison compare only (? 10 ?) compare and store (? 01 ?) adc1buf15 ? ? adc1buf14 ? ? adc1buf13 ? ? adc1buf12 ? ? adc1buf11 ? ? adc1buf10 threshold 2 conversion value adc1buf9 ? ? adc1buf8 ? ? adc1buf7 ? ? adc1buf6 ? ? adc1buf5 ? ? adc1buf4 ? ? adc1buf3 ? ? adc1buf2 threshold 1 threshold 1 adc1buf1 ? ? adc1buf0 ? ? ad1chitl 15 14 13 12 11 10 9 8 00000000 76543210 00000000
? 2012 microchip technology inc. ds30575a-page 475 pic18f97j94 family figure 22-15: outside window compar ison operation (under threshold 1) 22.8 examples 22.8.1 initialization example 22-1 shows a simple initialization code example for the a/d module. operation in idle mode is disabled, output data is in unsigned fractional format, and av dd and av ss are used for vr+ and vr-. the start of sampling, as well as the start of conversion (conversion trigger), are performed directly in software. scanning of inputs is disabled and an interrupt occurs after every sample/convert sequence (one conversion result) with only one channel (an0) being converted. the a/d conversion clock is tcy/2. in this particular configuration, all 16 analog input pins are set up as analog inputs. it is important to note that with this a/d module, i/o pins are configured for analog or digital operation at the i/o port with the ansn analog select registers. the use of these registers is described in detail in the i/o port chapter of the specific device data sheet. this example shows one method of controlling a sample/convert sequence by manually setting and clearing the samp bit (adcon1l<1>). this method, among others, is more fully discussed in section 22.4 ?controlling the sampling process? and section 22.5 ?controlling the conversion process? . adc1buf15 ? adc1buf14 ? adc1buf13 ? adc1buf12 ? adc1buf11 ? adc1buf10 threshold 2 adc1buf9 ? adc1buf8 ? adc1buf7 ? adc1buf6 ? adc1buf5 ? adc1buf4 ? adc1buf3 ? adc1buf2 threshold 1 adc1buf1 ? adc1buf0 ? before conversion and comparison ad1chitl 15 14 13 12 11 10 9 8 00000000 76543 2 10 00000 1 00 after conversion and comparison compare only (? 10 ?) compare and store (? 01 ?) adc1buf15 ? ? adc1buf14 ? ? adc1buf13 ? ? adc1buf12 ? ? adc1buf11 ? ? adc1buf10 threshold 2 threshold 2 adc1buf9 ? ? adc1buf8 ? ? adc1buf7 ? ? adc1buf6 ? ? adc1buf5 ? ? adc1buf4 ? ? adc1buf3 ? ? adc1buf2 threshold 1 conversion value adc1buf1 ? ? adc1buf0 ? ? ad1chitl 15 14 13 12 11 10 9 8 00000000 76543210 00000000
pic18f97j94 family ds30575a-page 476 ? 2012 microchip technology inc. example 22-3: a/d initialization code example adcon1h = 0x22; // configure sample clock source adcon1l = 0x00; // and conversion trigger mode. // unsigned fraction format (form<1:0>=10), // manual conversion trigger (ssrc<3:0>=0000), // manual start of sampling (asam=0), // no operation in idle mode (adsidl=1), // s/h in sample (samp = 1) adcon2h = 0; // configure a/d voltage reference adcon2l = 0; // and buffer fill modes. // vr+ and vr- from avdd and avss(pvcfg<1:0>=00, nvcfg=0), // inputs are not scanned, // interrupt after every sample adcon3h = 0; // configure sample time = 1tad, adcon3l = 0; // a/d conversion clock as tcy adchs0h = 0; // configure input channels, adchs0l = 0; // s/h+ input is an0, // s/h- input is vr- (avss). adcss0l = 0; // no inputs are scanned. adcss0h = 0; // no inputs are scanned. pir1bits.adif = 0; // clear a/d conversion interrupt. // configure a/d interrupt priority bits (adip) here, if // required. default priority level is high. pie1bits.adie = 1; // enable a/d conversion interrupt adcon1hbits.adon = 1; // turn on a/d adcon1lbits.samp = 1; // start sampling the input delay(); // ensure the correct sampling time has elapsed // before starting conversion. adcon1lbits.samp = 0; // end a/d sampling and start conversion // example code for a/d isr: #pragma interrupt _adc1interrupt void _adc1interrupt(void) { pir1bits.adif = 0; }
? 2012 microchip technology inc. ds30575a-page 477 pic18f97j94 family 22.8.2 conversion sequence examples the following configuration examples show the a/d operation in different sampling and buffering configura- tions. in each example, setting the asam bit starts automatic sampling. a conversion trigger ends sampling and starts conversion. 22.8.2.1 sampling and converting a single channel multiple times in this case figure 22-16 , one a/d input, an0, will be sampled and converted. the results are stored in the adcbufn buffer. this process repeats 16 times until the buffer is full and then the module generates an interrupt. the entire process will then repeat. with the alts bit clear, only the mux a inputs are active. the ch0sax and ch0nax bits are specified (an0 - vr-) as the inputs to the sample-and-hold channel. all other input selection bits are unused. figure 22-16: converting one channel 16 times per interrupt conversion a/d clk samp adc1buf0 t samp t conv bsf ad1con1, asam adc1buf1 done adc1bufe adc1buff analog input an0 t samp t conv an0 t samp t conv an0 t samp t conv an0 ad1if asam trigger instruction execution
pic18f97j94 family ds30575a-page 478 ? 2012 microchip technology inc. example 22-4: converting a sing le channel 16 times per interrupt a/d configuration: ? select an0 for s/h+ input (ch0sa<4:0> = 00000 ) ?select v r - for s/h- input (ch0na<2:0> = 000 ) ? configure for no input scan (cscna = 0 ) ? use only mux a for sampling (alts = 0 ) ? set ad1if on every 16th sample (smpi<4:0> = 01111 ) ? configure buffers for single, 16-word results (bufm = 0 ) operational sequence: 1. sample mux a input an0; convert and write to buffer 0h. 2. sample mux a input an0; convert and write to buffer 1h. 3. sample mux a input an0; convert and write to buffer 2h. 4. sample mux a input an0; convert and write to buffer 3h. 5. sample mux a input an0; convert and write to buffer 4h. 6. sample mux a input an0; convert and write to buffer 5h. 7. sample mux a input an0; convert and write to buffer 6h. 8. sample mux a input an0; convert and write to buffer 7h. 9. sample mux a input an0; convert and write to buffer 8h. 10. sample mux a input an0; convert and write to buffer 9h. 11. sample mux a input an0; convert and write to buffer ah. 12. sample mux a input an0; convert and write to buffer bh. 13. sample mux a input an0; convert and write to buffer ch. 14. sample mux a input an0; convert and write to buffer dh. 15. sample mux a input an0; convert and write to buffer eh. 16. sample mux a input an0; convert and write to buffer fh. 17. set ad1if flag (and generate interrupt, if enabled). 18. repeat (1-16) after return from interrupt. results stored in buffer (after 2 cycles): buffer address buffer contents at 1st ad1if event buffer contents at 2nd ad1if event adc1buf0 an0, sample 1 an0, sample 17 adc1buf1 an0, sample 2 an0, sample 18 adc1buf2 an0, sample 3 an0, sample 19 adc1buf3 an0, sample 4 an0, sample 20 adc1buf4 an0, sample 5 an0, sample 21 adc1buf5 an0, sample 6 an0, sample 22 adc1buf6 an0, sample 7 an0, sample 23 adc1buf7 an0, sample 8 an0, sample 24 adc1buf8 an0, sample 9 an0, sample 25 adc1buf9 an0, sample 10 an0, sample 26 adc1bufa an0, sample 11 an0, sample 27 adc1bufb an0, sample 12 an0, sample 28 adc1bufc an0, sample 13 an0, sample 29 adc1bufd an0, sample 14 an0, sample 30 adc1bufe an0, sample 15 an0, sample 31 adc1buff an0, sample 16 an0, sample 32
? 2012 microchip technology inc. ds30575a-page 479 pic18f97j94 family 22.8.2.2 a/d conversions while scanning through all analog inputs figure 22-17 and example 22-5 illustrate a typical setup, where all available analog input channels are sampled and converted. in this instance, 16 analog inputs are assumed. the set cscna bit specifies scanning of the a/d inputs to the s/h positive input. other conditions are similar to those located in section section 22.8.2.1 ?sampling and converting a single channel multiple times? . initially, the an0 input is sampled and converted. the result is stored in the adcbufn buffer. then, the an1 input is sampled and converted. this process of scan- ning the inputs repeats 16 times, until the buffer is full, and then the module generates an interrupt. the entire process will then repeat. figure 22-17: scanning all 16 inputs per single interrupt conversion a/d clk samp adc1buf0 t samp t conv bset ad1con1, #asam adc1buf1 done adc1bufe adc1buff analog input an0 t samp t conv an1 t samp t conv an14 t samp t conv an15 ad1if asam trigger instruction execution
pic18f97j94 family ds30575a-page 480 ? 2012 microchip technology inc. example 22-5: scanning and converting all 16 channels per single interrupt a/d configuration: ? select any channel for s/h+ input (ch0sa<4:0> = xxxxx ) ?select v r - for s/h- input (ch0na<2:0> = 000 ) ? use only mux a for sampling (alts = 0 ) ? configure mux a for input scan (cscna = 1 ) ? include all analog channels in scanning (ad1cssl = 1111 1111 1111 1111 ) ? set ad1if on every 16th sample (smpi<4:0> = 01111 ) ? configure buffers for single, 16-word results (bufm = 0 ) operational sequence: 1. sample mux a input an0; convert and write to buffer 0h. 2. sample mux a input an1; convert and write to buffer 1h. 3. sample mux a input an2; convert and write to buffer 2h. 4. sample mux a input an3; convert and write to buffer 3h. 5. sample mux a input an4; convert and write to buffer 4h. 6. sample mux a input an5; convert and write to buffer 5h. 7. sample mux a input an6; convert and write to buffer 6h. 8. sample mux a input an7; convert and write to buffer 7h. 9. sample mux a input an8; convert and write to buffer 8h. 10. sample mux a input an9; convert and write to buffer 9h. 11. sample mux a input an10; convert and write to buffer ah. 12. sample mux a input an11; convert and write to buffer bh. 13. sample mux a input an12; convert and write to buffer ch. 14. sample mux a input an13; convert and write to buffer dh. 15. sample mux a input an14; convert and write to buffer eh. 16. sample mux a input an15; convert and write to buffer fh. 17. set ad1if flag (and generate interrupt, if enabled). 18. repeat (1-16) after return from interrupt. results stored in buffer (after 2 cycles): buffer address buffer contents at 1st ad1if event buffer contents at 2nd ad1if event adc1buf0 sample 1 (an0, sample 1) sample 17 (an0, sample 2) adc1buf1 sample 2 (an1, sample 1) sample 18 (an1, sample 2) adc1buf2 sample 3 (an2, sample 1) sample 19 (an2, sample 2) adc1buf3 sample 4 (an3, sample 1) sample 20 (an3, sample 2) adc1buf4 sample 5 (an4, sample 1) sample 21 (an4, sample 2) adc1buf5 sample 6 (an5, sample 1) sample 22 (an5, sample 2) adc1buf6 sample 7 (an6, sample 1) sample 23 (an6, sample 2) adc1buf7 sample 8 (an7, sample 1) sample 24 (an7, sample 2) adc1buf8 sample 9 (an8, sample 1) sample 25 (an8, sample 2) adc1buf9 sample 10 (an9, sample 1) sample 26 (an9, sample 2) adc1buf10 sample 11 (an10, sample 1) sample 27 (an10, sample 2) adc1buf11 sample 12 (an11, sample 1) sample 28 (an11, sample 2) adc1buf12 sample 13 (an12, sample 1) sample 29 (an12, sample 2) adc1buf13 sample 14 (an13, sample 1) sample 30 (an13, sample 2) adc1buf14 sample 15 (an14, sample 1) sample 31 (an14, sample 2) adc1buf15 sample 16 (an15, sample 1) sample 32 (an15, sample 2)
? 2012 microchip technology inc. ds30575a-page 481 pic18f97j94 family 22.8.3 using dual buffers figure 22-18 and example 22-6 demonstrate using dual buffers and alternating the buffer fill. setting the bufm bit enables dual buffers. in this example, an interrupt is generated after each sample. the bufm setting does not affect other operational parameters. first, the conversion sequence starts filling the buffer at adcbuf0. after the first interrupt occurs, the buffer begins to fill at adcbuf8. the bufs status bit is toggled after each interrupt. figure 22-18: converting a single channe l, once per interrupt, using dual, 8-word buffers a/d clk samp adc1buf0 bset ad1con1, #asam analog input an3 t samp ad1if adc1buf8 an3 t samp an3 t samp bufs conversion trigger t conv t conv t conv t conv t conv t conv t conv t conv t conv t conv bclr ifs0, #ad1if bclr ifs0, #ad1if t conv t conv instruction execution
pic18f97j94 family ds30575a-page 482 ? 2012 microchip technology inc. example 22-6: converting a single channe l, once per interrupt, dual buffer mode 22.8.3.1 using alternating mux a and mux b input selections figure 22-19 and example 22-7 demonstrate alternate sampling of the inputs assigned to mux a and mux b. setting the alts bit enables alternating input selec- tions. the first sample uses the mux a inputs specified by the ch0sax and ch0nax bits. the next sample uses the mux b inputs, specified by the ch0sbx and ch0nbx bits. this example also demonstrates use of the dual, 8-word buffers. an interrupt occurs after every 8th sample, resulting in filling eight words into the buffer on each interrupt. a/d configuration: ? select an3 for s/h+ input (ch0sa<4:0> = 00011 ) ?select v r - for s/h- input (ch0na<2:0> = 000 ) ? configure for no input scan (cscna = 0 ) ? use only mux a for sampling (alts = 0 ) ? set ad1if on every sample (smpi<4:0> = 00000 ) ? configure buffer as dual, 8-word segments (bufm = 1 ) operational sequence: 1. sample mux a input, an3; convert and write to buffer 0h. 2. set ad1if flag (and generate interrupt, if enabled); write access automatically switches to alternate buffer. 3. sample mux a input, an3; convert and write to buffer 8h. 4. set ad1if flag (and generate interrupt, if enabled); write access automatically switches to alternate buffer. 5. repeat (1-4). results stored in buffer (after 2 cycles): buffer address buffer contents at 1st ad1if event buffer contents at 2nd ad1if event adc1buf0 sample 1 (an3, sample 1) (undefined) adc1buf1 (undefined) (undefined) adc1buf2 (undefined) (undefined) adc1buf3 (undefined) (undefined) adc1buf4 (undefined) (undefined) adc1buf5 (undefined) (undefined) adc1buf6 (undefined) (undefined) adc1buf7 (undefined) (undefined) adc1buf8 (undefined) sample 2 (an3, sample 2) adc1buf9 (undefined) (undefined) adc1bufa (undefined) (undefined) adc1bufb (undefined) (undefined) adc1bufc (undefined) (undefined) adc1bufd (undefined) (undefined) adc1bufe (undefined) (undefined) adc1buff (undefined) (undefined)
? 2012 microchip technology inc. ds30575a-page 483 pic18f97j94 family figure 22-19: converting two inputs using alternating input selections a/d clk samp adc1buf0 adc1buf1 done adc1buf2 adc1buf3 analog an1 t samp ad1if t conv adc1buf4 adc1buf5 adc1buf6 adc1buf7 an15 t samp t conv asam bufs an1 t samp t conv an15 t samp t conv adc1buf8 adc1buf9 adc1bufa adc1bufb t conv t samp an15 input conversion trigger cleared by software cleared in software t conv t conv t conv t conv t conv
pic18f97j94 family ds30575a-page 484 ? 2012 microchip technology inc. example 22-7: converting two inputs by alternating mux a and mux b a/d configuration: ? select an1 for mux a s/h+ input (ch0sa<4:0> = 00001 ) ?select v r - for mux a s/h- input (ch0na<2:0> = 000 ) ? configure for no input scan (cscna = 0 ) ? select an15 for mux b s/h+ input (ch0sb<4:0> = 11111 ) ?select v r - for mux b s/h- input (ch0nb<2:0> = 000 ) ? alternate mux a and mux b for sampling (alts = 1 ) ? set ad1if on every 8th sample (smpi<4:0> = 00111 ) ? configure buffer as two, 8-word segments (bufm = 1 ) operational sequence: 1. sample mux a input an1; convert and write to buffer 0h. 2. sample mux b input an15; convert and write to buffer 1h. 3. sample mux a input an1; convert and write to buffer 2h. 4. sample mux b input an15; convert and write to buffer 3h. 5. sample mux a input an1; convert and write to buffer 4h. 6. sample mux b input an15; convert and write to buffer 5h. 7. sample mux a input an1; convert and write to buffer 6h. 8. sample mux b input an15; convert and write to buffer 7h. 9. set ad1if flag (and generate interrupt, if enabled); write access automatically switches to alternate buffer. 10. repeat (1-9); resume writing to buffer with buffer 8h (first address of alternate buffer). results stored in buffer (after 2 cycles): buffer address buffer contents at 1st ad1if event buffer contents at 2nd ad1if event adc1buf0 sample 1 (an1, sample 1) (undefined) adc1buf1 sample 2 (an15, sample 1) (undefined) adc1buf2 sample 3 (an1, sample 2) (undefined) adc1buf3 sample 4 (an15, sample 2) (undefined) adc1buf4 sample 5 (an1, sample 3) (undefined) adc1buf5 sample 6 (an15, sample 3) (undefined) adc1buf6 sample 7 (an1, sample 4) (undefined) adc1buf7 sample 8 (an15, sample 4) (undefined) adc1buf8 (undefined) sample 9 (an1, sample 5) adc1buf9 (undefined) sample 10 (an15, sample 5) adc1bufa (undefined) sample 11 (an1, sample 6) adc1bufb (undefined) sample 12 (an15, sample 6) adc1bufc (undefined) sample 13 (an1, sample 7) adc1bufd (undefined) sample 14 (an15, sample 7) adc1bufe (undefined) sample 15 (an1, sample 8) adc1buff (undefined) sample 16 (an15, sample 8)
? 2012 microchip technology inc. ds30575a-page 485 pic18f97j94 family 22.9 a/d sampling requirements the analog input model of the 12-bit a/d converter is shown in figure 22-20 . the total sampling time for the a/d is a function of the holding capacitor charge time. for the a/d converter to meet its specified accuracy, the charge holding capacitor (chold) must be allowed to fully charge to the voltage level on the analog input pin. the source impedance (rs), the interconnect impedance (ric) and the internal sampling switch (rss) impedance combine to directly affect the time required to charge chold. the combined impedance of the analog sources must, therefore, be small enough to fully charge the holding capacitor within the chosen sample time. to minimize the effects of pin leakage currents on the accuracy of the a/d converter, the maximum recommended source impedance, rs, is 2.5 k. after the analog input channel is selected (changed), this sampling function must be completed prior to starting the conversion. the internal holding capacitor will be in a discharged state prior to each sample operation. at least 1 tad time period should be allowed between conversions for the sample time. for more details, see section 31.0 ?electrical characteristics? . figure 22-20: 12-bit a/d converter analog input model 22.10 transfer functions the transfer functions of the a/d converter, in 12-bit and 10-bit resolution, are shown in figure 22-21 and figure 22-22 , respectively. in both cases, the differ- ence of the input voltages, (vinh - vinl), is compared to the reference, ((vr+) - (vr-)). for the 12-bit transfer function: ? the first code transition occurs when the input voltage is ((vr+) - (vr-))/4096 or 1.0 lsb. ?the ' 0000 0000 0001 ' code is centered at vr- + (1.5 * ((vr+) - (vr-)) / 4096). ?the ' 0010 0000 0000 ' code is centered at vrefl + (2048.5 * ((vr+) - (vr-)) /4096). ? an input voltage less than vr- + (((vr-) - (vr-)) / 4096) converts as ' 0000 0000 0000 '. ? an input voltage greater than (vr-) + (4096 ((vr+) - (vr-))/4096) converts as ' 1111 1111 1111 '. c pin va rs anx i leakage r ic ? 250 ? sampling switch r ss c hold v ss = 4.4 pf ? 500 na legend: c pin v t i leakage r ic r ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch resistance = sample/hold capacitance (from dac) various junctions note: c pin value depends on device package and is not tested. the effect of the c pin is negligible if rs ? 5 k ? . r ss ? 3 k ?
pic18f97j94 family ds30575a-page 486 ? 2012 microchip technology inc. figure 22-21: 12-bit a/d transfer function for the 10-bit transfer function (when 10-bit resolution is available): ? the first code transition occurs when the input voltage is ((vr+) - (vr-))/1024 or 1.0 lsb. ?the ' 00 0000 0001 ' code is centered at vr- + (1.5 * (((vr+) - (vr-)) / 1024). ?the ' 10 0000 0000 ' code is centered at vrefl + (512.5 * (((vr+) - (vr-)) /1024). ? an input voltage less than vr- + (((vr-) - (vr-)) / 1024) converts as ' 00 0000 0000 '. ? an input voltage greater than (vr-) + ((1023 (vr+)) - (vr-))/1024) converts as ' 11 1111 1111 '. 0010 0000 0001 (2049) 0010 0000 0010 (2050) 0010 0000 0011 (2051) 0001 1111 1101 (2045) 0001 1111 1110 (2046) 0001 1111 1111 (2047) 1111 1111 1110 (4094) 1111 1111 1111 (4095) 0000 0000 0000 (0) 0000 0000 0001 (1) output code 0010 0000 0000 (2048) (v inh ? v inl ) v r - v r + ? v r - 4096 2048 * (v r + ? v r -) 4096 v r + v r - + v r - + 4095 * (v r + ? v r -) 4096 v r - + 0 (binary (decimal)) voltage level
? 2012 microchip technology inc. ds30575a-page 487 pic18f97j94 family figure 22-22: 10-bit a/d transfer function 22.11 operation during sleep and idle modes sleep and idle modes are useful for minimizing conver- sion noise because the digital activity of the cpu, buses and other peripherals is minimized. 22.11.1 cpu sleep mode without rc a/d clock when the device enters sleep mode, all clock sources to the module are shut down and stay at logic ' 0 '. if sleep occurs in the middle of a conversion, the conversion is aborted unless the a/d is clocked from its internal rc clock generator. the converter will not resume a partially completed conversion on exiting from sleep mode. register contents are not affected by the device entering or leaving sleep mode. 22.11.2 cpu sleep mode with rc a/d clock the a/d module can operate during sleep mode if the a/d clock source is set to the internal a/d rc oscillator (adrc = 1 ). this eliminates digital switching noise from the conversion. when the conversion is completed, the done bit will be set and the result is loaded into the a/d result buffer n, adcbufn. if the a/d interrupt is enabled (adie = 1 ), the device will wake-up from sleep when the a/d interrupt occurs. program execution will resume at the a/d interrupt service routine (isr). after the isr completes execu- tion will continue from the instruction after the sleep instruction that placed the device in sleep mode. if the a/d interrupt is not enabled, the a/d module will then be turned off, although the adon bit will remain set. 10 0000 0001 (513) 10 0000 0010 (514) 10 0000 0011 (515) 01 1111 1101 (509) 01 1111 1110 (510) 01 1111 1111 (511) 11 1111 1110 (1022) 11 1111 1111 (1023) 00 0000 0000 (0) 00 0000 0001 (1) output code 10 0000 0000 (512) (v inh ? v inl ) v r - v r + ? v r - 1024 512 * (v r + ? v r -) 1024 v r + v r - + v r - + 1023 * (v r + ? v r -) 1024 v r - + 0 (binary (decimal)) voltage level
pic18f97j94 family ds30575a-page 488 ? 2012 microchip technology inc. to minimize the effects of digital noise on the a/d module operation, the user should select a conversion trigger source that ensures the a/d conversion will take place in sleep mode. the automatic conversion trigger option can be used for sampling and conversion in sleep (ssrc<3:0> = 0111 ). to use the automatic conversion option, the adon bit should be set in the instruction prior to the sleep instruction. 22.11.3 a/d operation during cpu idle mode the adsidl bit (adcon1h<5>) determines whether the module stops or continues operation on idle. if adsidl = 0 , the module will continue normal operation when the device enters idle mode. if the a/d interrupt is enabled (adie = 1 ), the device will wake-up from idle mode when the a/d interrupt occurs. program execu- tion will resume at the a/d interrupt service routine (isr). after the isr completes execution will continue from the instruction after the sleep instruction that placed the device in idle mode. if adsidl = 1 , the module will stop in idle. if the device enters idle mode in the middle of a conversion, the conversion is aborted. the converter will not resume a partially completed conversion on exiting from idle mode. 22.11.4 peripheral module disable (pmd) register the peripheral module disable (pmd) registers provide a method to disable the a/d module by stop- ping all clock sources supplied to that module. when a peripheral is disabled via the appropriate pmdx control bit, the peripheral is in a minimum power consumption state. the control and status registers associated with the peripheral will also be disabled, so writes to those registers will have no effect and read values will be invalid. the a/d module is enabled only when the adcmd bit in the pmd3 register is cleared. 22.12 design tips question 1: how can i optimize the system perfor- mance of the a/d converter? answer: there are three main things to consider in optimizing a/d performance: 1. make sure you are meeting all of the timing specifications. if you are turning the module off and on, there is a minimum delay you must wait before taking a sample. if you are changing input channels, there is a minimum delay you must wait for this as well, and finally, there is tad, which is the time selected for each bit conversion. this is selected in ad1con3 and should be within a certain range, as specified in section 31.0 ?electrical characteristics? . if tad is too short, the result may not be fully con- verted before the con- version is terminated, and if tad is made too long, the voltage on the sam- pling capacitor can decay before the conversion is complete. these timing specifications are provided in the ?electrical characteristics? section of the device data sheets. 2. often, the source impedance of the analog signal is high (greater than 2.5 k ? ), so the current drawn from the source by leakage, and to charge the sample capacitor, can affect accuracy. if the input signal does not change too quickly, try putting a 0.1 uf capacitor on the analog input. this capacitor will charge to the analog voltage being sampled and supply the instantaneous current needed to charge the internal holding capacitor. 3. put the device into sleep mode before the start of the a/d conversion. the rc clock source selection is required for conversions in sleep mode. this technique increases accuracy, because digital noise from the cpu and other peripherals is minimized. question 2: do you know of a good reference on a/d converters? answer: a good reference for understanding a/d conversions is the ?analog-digital conversion handbook third edition, published by prentice hall (isbn 0-13-03-2848-0). question 3: my combination of channels/samples and samples/interrupt is greater than the size of the buffer. what will happen to the buffer? answer: this configuration is not recommended. the buffer will contain unknown results. 22.13 related application notes this section lists application notes that are related to this section of the data sheet. these application notes may not be written specifically for the pic18f device family, but the concepts are pertinent and could be used with modification and possible limitations. the current application notes related to the 12-bit a/d converter with threshold detect module are: an546, using the analog-to-digital (a/d) converter (ds00546) an557, four-channel digital voltmeter with display and keyboard (ds00557) an693, understanding a/d converter performance specifications (ds00693) note: for the a/d module to operate in sleep, the a/d clock source must be set to rc (adrc = 1 ). note: please visit the microchip web site ( www.microchip.com) for additional application notes and code examples for the pic18f family of devices.
? 2012 microchip technology inc. ds30575a-page 489 pic18f97j94 family 23.0 comparator module the analog comparator module contains three compar- ators that can be independently configured in a variety of ways. the inputs can be selected from the analog inputs and two internal voltage references. the digital outputs are available at the pin level, via pps-lite, and can also be read through the control register. multiple output and interrupt event generations are also avail- able. a generic single comparator from the module is shown in figure 23-1 . key features of the module includes: ? independent comparator control ? programmable input configuration ? output to both pin and register levels ? programmable output polarity ? independent interrupt generation for each comparator with configurable interrupt-on-change 23.1 registers the cmxcon registers (cm1con, cm2con and cm3con) select the input and output configuration for each comparator, as well as the settings for interrupt generation (see register 23-1 ). the cmstat register ( register 23-2 ) provides the out- put results of the comparators. the bits in this register are read-only. figure 23-1: comparator simplified block diagram cx v in - v in + coe cxout 0 1 2 0 1 cch<1:0> cxinb cxinc c2inb/c2ind (1) cxina cv ref con interrupt logic evpol<1:0> cxout (cmstat<2:0>) cmpxif cpol polarity logic cref 3 v bg note 1: comparator 1 and comparator 3 use c2inb as an input to the inverted terminal. comparator 2 uses c2ind as an input to the inverted terminal.
pic18f97j94 family ds30575a-page 490 ? 2012 microchip technology inc. register 23-1: cmxcon: comparator control x register r/w-0 r/w-0 r/w-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 con coe cpol evpol1 evpol0 cref cch1 cch0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 con: comparator enable bit 1 = comparator is enabled 0 = comparator is disabled bit 6 coe: comparator output enable bit 1 = comparator output is present on the cxout pin 0 = comparator output is internal only bit 5 cpol: comparator output polarity select bit 1 = comparator output is inverted 0 = comparator output is not inverted bit 4-3 evpol<1:0>: interrupt polarity select bits 11 = interrupt generation on any change of the output ( 1 ) 10 = interrupt generation only on high-to-low transition of the output 01 = interrupt generation only on low-to-high transition of the output 00 = interrupt generation is disabled bit 2 cref: comparator reference select bit (non-inverting input) 1 = non-inverting input connects to internal cv ref voltage 0 = non-inverting input connects to cxina pin bit 1-0 cch<1:0>: comparator channel select bits 11 = inverting input of comparator connects to v bg 10 = inverting input of comparator connects to cxinb pin 01 = inverting input of comparator connects to cxinc pin 00 = inverting input of comparator connects to c2inb pin ( 2 ) note 1: the cmpxif is automatically set any time this mode is selected and must be cleared by the application after the initial configuration. 2: comparator 1 and comparator 3 use c2inb as an input to the inverting terminal. comparator 2 uses c2inb as an input to the inverted terminal.
? 2012 microchip technology inc. ds30575a-page 491 pic18f97j94 family register 23-2: cmstat: comparator status register u-0 u-0 u-0 u-0 u-0 r-x r-x r-x ? ? ? ? ? c3out c2out c1out bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-3 unimplemented: read as ? 0 ? bit 2-0 c3out:c1out: comparator x status bits if cpol (cmxcon<5>)= 0 (non-inverted polarity) : 1 = comparator x?s v in + > v in - 0 = comparator x?s v in + < v in - cpol = 1 (inverted polarity) : 1 = comparator x?s v in + < v in - 0 = comparator x?s v in + > v in -
pic18f97j94 family ds30575a-page 492 ? 2012 microchip technology inc. 23.2 comparator operation a single comparator is shown in figure 23-2 , along with the relationship between the analog input levels and the digital output. when the analog input at v in + is less than the analog input, v in -, the output of the compara- tor is a digital low level. when the analog input at v in + is greater than the analog input, v in -, the output of the comparator is a digital high level. the shaded areas of the output of the comparator in figure 23-2 represent the uncertainty due to input offsets and response time. figure 23-2: single comparator 23.3 comparator response time response time is the minimum time, after selecting a new reference voltage or input source, before the com- parator output has a valid level. the response time of the comparator differs from the settling time of the volt- age reference. therefore, both of these times must be considered when determining the total response to a comparator input change. otherwise, the maximum delay of the comparators should be used (see section 31.0 ?electrical characteristics? ). 23.4 analog input connection considerations a simplified circuit for an analog input is shown in figure 23-3 . since the analog pins are connected to a digital output, they have reverse biased diodes to v dd and v ss . the analog input, therefore, must be between v ss and v dd . if the input voltage deviates from this range by more than 0.6v in either direction, one of the diodes is forward biased and a latch-up condition may occur. a maximum source impedance of 10 k ? is recommended for the analog sources. any external component connected to an analog input pin, such as a capacitor or a zener diode, should have very little leakage current. figure 23-3: comparator analog input model output v in - v in + v in + v in - + ? output va r s a in c pin 5 pf v dd r ic i leakage 100 na v ss legend: c pin = input capacitance v t = threshold voltage i leakage = leakage current at the pin due to various junctions r ic = interconnect resistance r s = source impedance va = analog voltage comparator input <10 k ?
? 2012 microchip technology inc. ds30575a-page 493 pic18f97j94 family 23.5 comparator control and configuration each comparator has up to eight possible combina- tions of inputs: up to four external analog inputs and one of two internal voltage references. all of the comparators allow a selection of the signal from pin, cxina, or the voltage from the comparator reference (cv ref ) on the non-inverting channel. this is compared to either cxinb, cxinc, c2ind or the microcontroller?s fixed internal reference voltage (v bg , 1.2v nominal) on the inverting channel. the compara- tor inputs and outputs are tied to fixed i/o pins, defined in table 23-1 . the available comparator configurations and their corresponding bit settings are shown in figure 23-4 . table 23-1: comparator inputs and outputs 23.5.1 comparator enable and input selection setting the con bit of the cmxcon register (cmxcon<7>) enables the comparator for operation. clearing the con bit disables the comparator, resulting in minimum current consumption. the cch<1:0> bits in the cmxcon register (cmxcon<1:0>) direct either one of three analog input pins, or the internal reference voltage (v bg ), to the comparator, v in -. depending on the comparator oper- ating mode, either an external or internal voltage reference may be used. the analog signal present at v in - is compared to the signal at v in + and the digital output of the comparator is adjusted accordingly. the external reference is used when cref = 0 (cmxcon<2>) and v in + is connected to the cxina pin. when external voltage references are used, the comparator module can be configured to have the ref- erence sources externally. the reference signal must be between v ss and v dd and can be applied to either pin of the comparator. the comparator module also allows the selection of an internally generated voltage reference from the compar- ator voltage reference (cv ref ) module. this module is described in more detail in section 24.0 ?comparator voltage reference module? . the reference from the comparator voltage reference module is only available when cref = 1 . in this mode, the internal voltage reference is applied to the comparator?s v in + pin. 23.5.2 comparator enable and output selection the comparator outputs are read through the cmstat register. the cmstat<0> bit reads the comparator 1 output, cmstat<2> reads the comparator 2 output and the cmstat<3> bit reads the comparator 3 output these bits are read-only. the comparator outputs may also be directly output to the rpn i/o pins by setting the coe bit (cmxcon<6>). when enabled, multiplexers in the output path of the pins switch to the output of the comparator. while in this mode, the respective trisx bits still function as the digital output enable bits for the rpn i/o pins. comparator input or output i/o pin ( ? ) 1 c1ina (v in +) ra5/rf6 c1inb (v in -) rf5 c1inc (v in -) rh6 ( 2 ) c2inb(v in -) rf2 cv ref (v in +) rf5 c1out rpn ( 1 ) 2 c2ina (v in +) ra5 c2inb (v in -) rf2 c2inc (v in -) rh4 ( 2 ) c2ind (v in -) rh5 ( 2 ) cv ref (v in +) rf5 c2out rpn ( 1 ) 3 c3ina (v in +) ra5/rg2 c3inb (v in -) rg3 c2inb (v in -) rf2 c3inc (v in -) rg4 cv ref (v in +) rf5 c3out rpn ( 1 ) ? the i/o pin is dependent on package type. note 1: these pins are remappable i/os. 2: these pins are not available on 64-pin devices. note: the comparator input pin selected by cch<1:0> must be configured as an input by setting both the corresponding trisx bit and the corresponding anselx bit in the anconx register.
pic18f97j94 family ds30575a-page 494 ? 2012 microchip technology inc. by default, the comparator?s output is at logic high whenever the voltage on v in + is greater than on v in -. the polarity of the comparator outputs can be inverted using the cpol bit (cmxcon<5>). the uncertainty of each of the comparators is related to the input offset voltage and the response time given in the specifications, as discussed in section 23.2 ?comparator operation? . figure 23-4: comparator configurations cx v in - v in + off (read as ? 0 ?) comparator off con = 0 , cref = x , cch<1:0> = xx coe cx v in - v in + coe comparator cxinb > cxina compare con = 1 , cref = 0 , cch<1:0> = 00 cxinb cxina cx v in - v in + coe comparator cxinc > cxina compare con = 1 , cref = 0 , cch<1:0> = 01 cxinc cxina cx v in - v in + coe comparator c2ind/c2inb > cxina compare con = 1 , cref = 0 , cch<1:0> = 10 c2inb cxina cx v in - v in + coe comparator v bg > cxina compare con = 1 , cref = 0 , cch<1:0> = 11 v bg cxina cx v in - v in + coe comparator cxinb > cv ref compare con = 1 , cref = 1 , cch<1:0> = 00 cxinb cv ref cx v in - v in + coe comparator cxinc > cv ref compare con = 1 , cref = 1 , cch<1:0> = 01 cxinc cv ref cx v in - v in + coe comparator c2ind/c2inb > cv ref compare con = 1 , cref = 1 , cch<1:0> = 10 cv ref cx v in - v in + coe pin comparator v bg > cv ref compare con = 1 , cref = 1 , cch<1:0> = 11 v bg cv ref cxout note 1: v bg is the internal reference voltage (see table 31-10 ). pin cxout pin cxout pin cxout pin cxout pin cxout pin cxout pin cxout pin cxout c2ind/ c2inb c2ind/
? 2012 microchip technology inc. ds30575a-page 495 pic18f97j94 family 23.6 comparator interrupts the comparator interrupt flag is set whenever any of the following occurs: ? low-to-high transition of the comparator output ? high-to-low transition of the comparator output ? any change in the comparator output the comparator interrupt selection is done by the evpol<1:0> bits in the cmxcon register (cmxcon<4:3>). in order to provide maximum flexibility, the output of the comparator may be inverted using the cpol bit in the cmxcon register (cmxcon<5>). this is functionally identical to reversing the inverting and non-inverting inputs of the comparator for a particular mode. an interrupt is generated on the low-to-high or high-to- low transition of the comparator output. this mode of interrupt generation is dependent on evpol<1:0> in the cmxcon register. when evpol<1:0> = 01 or 10 , the interrupt is generated on a low-to-high or high-to- low transition of the comparator output. once the interrupt is generated, it is required to clear the interrupt flag by software. when evpol<1:0> = 11 , the comparator interrupt flag is set whenever there is a change in the output value of either comparator. software will need to maintain information about the status of the output bits, as read from cmstat<2:0>, to determine the actual change that occurred. the cmpxif<2:0> (pir6<2:0>) bits are the compara- tor interrupt flags. the cmpxif bits must be reset by clearing them. since it is also possible to write a ? 1 ? to this register, a simulated interrupt may be initiated. table 23-2 shows the interrupt generation with respect to comparator input voltages and evpol bit settings. both the cmpxie bits (pie6<2:0>) and the peie bit (intcon<6>) must be set to enable the interrupt. in addition, the gie bit (intcon<7>) must also be set. if any of these bits are clear, the interrupt is not enabled, though the cmpxif bits will still be set if an interrupt condition occurs. a simplified diagram of the interrupt section is shown in figure 23-3 . table 23-2: comparator interrupt generation note: cmpxif will not be set when evpol<1:0> = 00 . cpol evpol<1:0> comparator input change cxout transition interrupt generated 0 00 v in + > v in - low-to-high no v in + < v in -high-to-low no 01 v in + > v in - low-to-high yes v in + < v in -high-to-low no 10 v in + > v in - low-to-high no v in + < v in -high-to-low yes 11 v in + > v in - low-to-high yes v in + < v in -high-to-low yes 1 00 v in + > v in -high-to-low no v in + < v in - low-to-high no 01 v in + > v in -high-to-low no v in + < v in - low-to-high yes 10 v in + > v in -high-to-low yes v in + < v in - low-to-high no 11 v in + > v in -high-to-low yes v in + < v in - low-to-high yes
pic18f97j94 family ds30575a-page 496 ? 2012 microchip technology inc. 23.7 comparator operation during sleep when a comparator is active and the device is placed in sleep mode, the comparator remains active and the interrupt is functional, if enabled. this interrupt will wake-up the device from sleep mode when enabled. each operational comparator will consume additional current. to minimize power consumption while in sleep mode, turn off the comparators (con = 0 ) before entering sleep. if the device wakes up from sleep, the contents of the cmxcon register are not affected. 23.8 effects of a reset a device reset forces the cmxcon registers to their reset state. this forces both comparators and the voltage reference to the off state.
? 2012 microchip technology inc. ds30575a-page 497 pic18f97j94 family 24.0 comparator voltage reference module the comparator voltage reference is a 32-tap resistor ladder network that provides a selectable reference voltage. although its primary purpose is to provide a reference for the analog comparators, it may also be used independently of them. a block diagram of the module is shown in figure 24-1 . the resistor ladder is segmented to provide a range of cv ref values and has a power-down function to conserve power when the reference is not being used. the module?s supply reference can be provided from either device v dd /v ss or an external voltage reference. 24.1 configuring the comparator voltage reference the comparator voltage reference module is controlled through the cvrconh register ( register 24-1 ). the comparator voltage reference provides a range of output voltage with 32 levels. the cvr<4:0> selection bits (cvrconh<4:0>) offer a range of output voltages. equation 24-1 shows how the comparator voltage reference is computed. equation 24-1: the comparator voltage reference supply can come from either v dd and v ss , or the external v ref + and v ref - that are multiplexed with ra3 and ra2. the voltage source is selected by the cvrpss<1:0> bits (cvrconl<5:4>). the settling time of the comparator voltage reference must be considered when changing the cv ref out- put (see table 31-10 in section 31.0 ?electrical characteristics? ). if cvrss = 1 : cv ref = v ref - + ? (v ref + ? v ref -) cvr<4:0> 32 () if cvrss = 0 : cv ref = av ss + ? (av dd ? av ss ) cvr<4:0> 32 () register 24-1: cvrconh: comparator voltage reference control register high u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? cvr4 cvr3 cvr2 cvr1 cvr0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 cvr<4:0>: comparator v ref value selection 0 ? cvr<4:0> ? 31 bits cv ref = v negsrc + (cvr<4:0>/32) ? (v possrc ? v negsrc )
pic18f97j94 family ds30575a-page 498 ? 2012 microchip technology inc. figure 24-1: comparator voltage reference block diagram register 24-2: cvrconl: comparator voltage reference control register low r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 r/w-0 cvren cvroe cvrpss1 cvrpss0 ? ? ? cvrnss bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 cvren: comparator voltage reference enable bit 1 = cv ref circuit is powered on 0 = cv ref circuit is powered down bit 6 cvroe: comparator v ref output enable bit 1 = cv ref voltage level is output on cv ref pin 0 = cv ref voltage level is disconnected from cv ref pin bit 5-4 cvrpss<1:0>: comparator v ref positive source (v possrc ) selection bits 11 = reserved, do not use. positive source is floating 10 = v bg (band gap) 01 = v ref + 00 = av dd bit 3-1 unimplemented: read as ? 0 ? bit 0 cvrnss: comparator v ref negative source (v negsrc ) selection bit 01 = v ref - 00 = av ss 32-to-1 mux cvr<4:0> 8r r cvren cvrss = 0 av dd v ref + cvrss = 1 r r r r r r 32 steps cv ref v ref - cvrss = 1 cvrss = 0
? 2012 microchip technology inc. ds30575a-page 499 pic18f97j94 family 24.2 voltage reference accuracy/error the full range of voltage reference cannot be realized due to the construction of the module. the transistors on the top and bottom of the resistor ladder network ( figure 24-1 ) keep cv ref from approaching the refer- ence source rails. the voltage reference is derived from the reference source; therefore, the cv ref output changes with fluctuations in that source. the tested absolute accuracy of the voltage reference can be found in section 31.0 ?electrical characteristics? . 24.3 operation during sleep when the device wakes up from sleep through an interrupt or a watchdog timer time-out, the contents of the cvrcon register are not affected. to minimize current consumption in sleep mode, the voltage reference should be disabled. 24.4 effects of a reset a device reset disables the voltage reference by clearing bit, cvren (cvrconl<7>). this reset also disconnects the reference from the rf5 pin by clearing bit, cvroe (cvrconl<6>). 24.5 connection considerations the voltage reference module operates independently of the comparator module. the output of the reference generator may be connected to the ra0 pin if the cvroe bit is set. enabling the voltage reference out- put onto ra0, when it is configured as a digital input, will increase current consumption. connecting ra0 as a digital output with cvrss enabled will also increase current consumption. the ra0 pin can be used as a simple d/a output with limited drive capability. due to the limited current drive capability, a buffer must be used on the voltage reference output for external connections to v ref . figure 24-2 shows an example buffering technique. figure 24-2: comparator voltage reference output buffer example pic18f97j94 note 1: r is dependent upon the comparator voltage reference bits, cvrconh<4:0>, cvrconl<5:4> and cvrconl<0>. cv ref module r (1) voltage reference output impedance rf5 + ? cv ref output
pic18f97j94 family ds30575a-page 500 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 501 pic18f97j94 family 25.0 high/low-voltage detect (hlvd) the pic18f97j94 family of devices has a high/low- voltage detect module (hlvd). this is a programmable circuit that sets both a device voltage trip point and the direction of change from that point. if the device experi- ences an excursion past the trip point in that direction, an interrupt flag is set. if the interrupt is enabled, the pro- gram execution branches to the interrupt vector address and the software responds to the interrupt. the high/low-voltage detect control register ( register 25-1 ) completely controls the operation of the hlvd module. this allows the circuitry to be ?turned off? by the user under software control, which minimizes the current consumption for the device. the module?s block diagram is shown in figure 25-1 . register 25-1: hlvdcon: high/low-v oltage detect control register r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 vdirmag bgvst irvst hlvden hlvdl3 ( 1 ) hlvdl2 ( 1 ) hlvdl1 ( 1 ) hlvdl0 ( 1 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 vdirmag: voltage direction magnitude select bit 1 = event occurs when voltage equals or exceeds trip point (hlvdl<3:0>) 0 = event occurs when voltage equals or falls below trip point (hlvdl<3:0>) bit 6 bgvst: band gap reference voltages stable status flag bit 1 = internal band gap voltage references are stable 0 = internal band gap voltage references are not stable bit 5 irvst: internal reference voltage stable flag bit 1 = indicates that the voltage detect logic will generate the interrupt flag at the specified voltage range 0 = indicates that the voltage detect logic will not generate the interrupt flag at the specified voltage range and the hlvd interrupt should not be enabled bit 4 hlvden: high/low-voltage detect power enable bit 1 = hlvd is enabled 0 = hlvd is disabled bit 3-0 hlvdl<3:0>: voltage detection limit bits ( 1 ) 1111 = external analog input is used (input comes from the hlvdin pin) 1110 = maximum setting . . . 0100 = minimum setting note 1: for the electrical specifications, see parameter d420 .
pic18f97j94 family ds30575a-page 502 ? 2012 microchip technology inc. the module is enabled by setting the hlvden bit (hlvdcon<4>). each time the hlvd module is enabled, the circuitry requires some time to stabilize. the irvst bit (hlvdcon<5>) is a read-only bit used to indicate when the circuit is stable. the module can only generate an interrupt after the circuit is stable and irvst is set. the vdirmag bit (hlvdcon<7>) determines the overall operation of the module. when vdirmag is cleared, the module monitors for drops in v dd below a predetermined set point. when the bit is set, the module monitors for rises in v dd above the set point. 25.1 operation when the hlvd module is enabled, a comparator uses an internally generated reference voltage as the set point. the set point is compared with the trip point, where each node in the resistor divider represents a trip point voltage. the ?trip point? voltage is the voltage level at which the device detects a high or low-voltage event, depending on the configuration of the module. when the supply voltage is equal to the trip point, the voltage tapped off of the resistor array is equal to the internal reference voltage generated by the voltage reference module. the comparator then generates an interrupt signal by setting the hlvdif bit. the trip point voltage is software programmable to any of 16 values. the trip point is selected by programming the hlvdl<3:0> bits (hlvdcon<3:0>). the hlvd module has an additional feature that allows the user to supply the trip voltage to the module from an external source. this mode is enabled when bits, hlvdl<3:0>, are set to ? 1111 ?. in this state, the comparator input is multiplexed from the external input pin, hlvdin. this gives users the flexibility of configur- ing the high/low-voltage detect interrupt to occur at any voltage in the valid operating range. figure 25-1: hlvd module block diagram (with external input) set v dd 16-to-1 mux hlvden hlvdcon hlvdl<3:0> register hlvdin v dd externally generated trip point hlvdif hlvden boren internal voltage reference vdirmag 1.2v typical
? 2012 microchip technology inc. ds30575a-page 503 pic18f97j94 family 25.2 hlvd setup to set up the hlvd module: 1. select the desired hlvd trip point by writing the value to the hlvdl<3:0> bits. 2. set the vdirmag bit to detect high voltage (vdirmag = 1 ) or low voltage (vdirmag = 0 ). 3. enable the hlvd module by setting the hlvden bit. 4. clear the hlvd interrupt flag (pir2<2>), which may have been set from a previous interrupt. 5. if interrupts are desired, enable the hlvd inter- rupt by setting the hlvdie and gie bits (pie2<2> and intcon<7>, respectively). an interrupt will not be generated until the irvst bit is set. 25.3 current consumption when the module is enabled, the hlvd comparator and voltage divider are enabled and consume static current. depending on the application, the hlvd module does not need to operate constantly. to reduce current requirements, the hlvd circuitry may only need to be enabled for short periods where the voltage is checked. after such a check, the module could be disabled. 25.4 hlvd start-up time the internal reference voltage of the hlvd module, specified in electrical specification, parameter 37 ( section 31.0 ?electrical characteristics? ), may be used by other internal circuitry, such as the programmable brown-out reset. if the hlvd or other circuits using the voltage reference are disabled to lower the device?s current consumption, the reference voltage circuit will require time to become stable before a low or high-voltage condition can be reliably detected. this start-up time, t irvst , is an interval that is independent of device clock speed. it is specified in electrical specification, parameter 37 ( table 31-22 ). the hlvd interrupt flag is not enabled until t irvst has expired and a stable reference voltage is reached. for this reason, brief excursions beyond the set point may not be detected during this interval (see figure 25-2 or figure 25-3 ). note: before changing any module settings (v dirmag , hlvdl<3:0>), first disable the module (hlvden = 0 ), make the changes and re-enable the module. this prevents the generation of false hlvd events.
pic18f97j94 family ds30575a-page 504 ? 2012 microchip technology inc. figure 25-2: low-voltage detect operation (vdirmag = 0 ) figure 25-3: high-voltage detect operation (vdirmag = 1 ) v hlvd v dd hlvdif v hlvd v dd enable hlvd t irvst hlvdif will not be set enable hlvd hlvdif hlvdif cleared in software hlvdif cleared in software hlvdif cleared in software, case 1: case 2: hlvdif remains set since hlvd condition still exists t irvst internal reference is stable internal reference is stable irvst irvst v hlvd v dd hlvdif v hlvd v dd enable hlvd t irvst hlvdif will not be set enable hlvd hlvdif hlvdif cleared in software hlvdif cleared in software hlvdif cleared in software, case 1: case 2: hlvdif remains set since hlvd condition still exists t irvst irvst internal reference is stable internal reference is stable irvst
? 2012 microchip technology inc. ds30575a-page 505 pic18f97j94 family 25.5 applications in many applications, it is desirable to detect a drop below, or rise above, a particular voltage threshold. for example, the hlvd module could be periodically enabled to detect universal serial bus (usb) attach or detach. this assumes the device is powered by a lower voltage source than the usb when detached. an attach would indicate a high-voltage detect from, for example, 3.3v to 5v (the voltage on usb) and vice versa for a detach. this feature could save a design a few extra components and an attach signal (input pin). for general battery applications, figure 25-4 shows a possible voltage curve. over time, the device voltage decreases. when the device voltage reaches voltage, v a , the hlvd logic generates an interrupt at time, t a . the interrupt could cause the execution of an isr, which would allow the application to perform ?housekeeping tasks? and a controlled shutdown, before the device voltage exits the valid operating range at t b . this would give the application a time window, represented by the difference between t a and t b , to safely exit. figure 25-4: typical low-voltage detect application 25.6 operation during sleep when enabled, the hlvd circuitry continues to operate during sleep. if the device voltage crosses the trip point, the hlvdif bit will be set and the device will wake-up from sleep. device execution will continue from the interrupt vector address if interrupts have been globally enabled. 25.7 effects of a reset a device reset forces all registers to their reset state. this forces the hlvd module to be turned off. time voltage v a v b t a t b v a = hlvd trip point v b = minimum valid device operating voltage legend:
pic18f97j94 family ds30575a-page 506 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 507 pic18f97j94 family 26.0 charge time measurement unit (ctmu) the charge time measurement unit (ctmu) is a flexible analog module that provides accurate differen- tial time measurement between pulse sources, as well as asynchronous pulse generation. by working with other on-chip analog modules, the ctmu can precisely measure time, capacitance and relative changes in capacitance or generate output pulses with a specific time delay. the ctmu is ideal for interfacing with capacitive-based sensors. the module includes these key features: ? up to 24 channels available for capacitive or time measurement input ? low-cost temperature measurement using on-chip diode channel ? on-chip precision current source ? sixteen-edge input trigger sources ? polarity control for each edge source ? provides a trigger for the a/d converter ? control of edge sequence ? control of response to edges ? time measurement resolution of 1 nanosecond ? high-precision time measurement ? time delay of external or internal signal asynchronous to system clock ? accurate current source suitable for capacitive measurement the ctmu works in conjunction with the a/d converter to provide up to 24 channels for time or charge measurement, depending on the specific device and the number of a/d channels available. when config- ured for time delay, the ctmu is connected to one of the analog comparators. the level-sensitive input edge sources can be selected from four sources: two external inputs or the ccp1/ccp2 special event triggers. the ctmu special event can trigger the analog-to-digital converter module. figure 26-1 provides a block diagram of the ctmu. figure 26-1: ctmu block diagram cted1 cted2 current source edge control logic ctmuconh:ctmuconl pulse generator a/d converter comparator 2 input ccp2 ccp1 current control itrim<5:0> irng<1:0> ctmucon1 ctmu control logic edgen edgseqen edg1sel<1:0> edg1pol edg2sel<1:0> edg2pol edg1stat edg2stat tgen idissen cttrig a/d trigger ctpls comparator 2 output
pic18f97j94 family ds30575a-page 508 ? 2012 microchip technology inc. 26.1 ctmu registers the control registers for the ctmu are: ? ctmucon1 ? ctmucon2 ? ctmucon3 ? ctmucon4 the ctmucon1 and ctmucon3 registers ( register 26-1 and register 26-3 ) contain control bits for configuring the ctmu module edge source selec- tion, edge source polarity selection, edge sequencing, a/d trigger, analog circuit capacitor discharge and enables. the ctmucon2 register ( register 26-2 ) has bits for selecting the current source range and current source trim. register 26-1: ctmucon1: ct mu control register 1 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ctmuen ? ctmusidl tgen edgen edgseqen idissen cttrig bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ctmuen: ctmu enable bit 1 = module is enabled 0 = module is disabled bit 6 unimplemented: read as ? 0 ? bit 5 ctmusidl: stop in idle mode bit 1 = discontinues module operation when device enters idle mode 0 = continues module operation in idle mode bit 4 tgen: time generation enable bit 1 = enables edge delay generation 0 = disables edge delay generation bit 3 edgen: edge enable bit 1 = edges are not blocked 0 = edges are blocked bit 2 esgseqen: edge sequence enable bit 1 = edge 1 event must occur before edge 2 event can occur 0 = no edge sequence is needed bit 1 idissen: analog current source control bit 1 = analog current source output is grounded 0 = analog current source output is not grounded bit 0 cttrig: ctmu special event trigger bit 1 = ctmu special event trigger is enabled 0 = ctmu special event trigger is disabled
? 2012 microchip technology inc. ds30575a-page 509 pic18f97j94 family register 26-2: ctmucon2: ctmu current control register 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 itrim5 itrim4 itrim3 itrim2 itrim1 itrim0 irng1 irng0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 itrim<5:0>: current source trim bits 011111 = maximum positive change (+62% typ.) from nominal current 011110 . . . 000001 = minimum positive change (+2% typ.) from nominal current 000000 = nominal current output specified by irng<1:0> 111111 = minimum negative change (-2% typ.) from nominal current . . . 100010 100001 = maximum negative change (-62% typ.) from nominal current bit 1-0 irng<1:0>: current source range select bits 11 = 100 x base current 10 = 10 x base current 01 = base current level (0.55 ? a nominal) 00 = 1000 x base current
pic18f97j94 family ds30575a-page 510 ? 2012 microchip technology inc. register 26-3: ctmucon3: ctmu current control register 3 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 edg2en edg2pol edg2sel3 edg 2sel2 edg2sel1 edg2sel0 ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 edg2en: edge 2 edge-sensitive select bit 1 = input is edge-sensitive 0 = input is level-sensitive bit 6 edg2pol: edge 2 polarity select bit 1 = edge 2 is programmed for a positive edge response 0 = edge 2 is programmed for a negative edge response bit 5-2 edg2sel<3:0>: edge 2 source select bits 1111 = cmp3 selected 1110 = cmp2 selected 1101 = cmp1 selected 1100 = reserved 1011 = ccp3 trigger selected 1010 = ccp2 trigger selected 1001 = ccp1 trigger selected 1000 = cted13 selected 0111 = cted12 selected 0110 = cted11 selected 0101 = cted10 selected 0100 = cted9 selected 0011 = cted1 selected 0010 = cted2 selected 0001 = ccp1 interrupt selected 0000 = tmr1 interrupt selected bit 1-0 unimplemented: read as ? 0 ?
? 2012 microchip technology inc. ds30575a-page 511 pic18f97j94 family register 26-4: ctmucon4: ctmu current control register 4 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 edg1en edg1pol edg1sel3 edg1sel2 ed g1sel1 edg1sel0 edg2stat edg1stat bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 edg1en: edge 1 edge-sensitive select bit 1 = input is edge-sensitive 0 = input is level-sensitive bit 6 edg1pol: edge 1 polarity select bit 1 = edge 1 is programmed for a positive edge response 0 = edge 1 is programmed for a negative edge response bit 5-2 edg1sel<3:0>: edge 1 source select bits 1111 = cmp3 selected 1110 = cmp2 selected 1101 = cmp1 selected 1100 = ccp3 trigger selected 1011 = ccp2 trigger selected 1010 = ccp1 trigger selected 1001 = cted8 selected 1000 = cted7 selected 0111 = cted6 selected 0110 = cted5 selected 0101 = cted4 selected 0100 = cted3 selected 0011 = cted1 selected 0010 = cted2 selected 0001 = ccp1 interrupt selected 0000 = tmr1 interrupt selected bit 1-0 edg2stat: edge 2 status bit indicates the status of edge 2 and can be written to control edge source. 1 = edge2 has occurred 0 = edge2 has not occurred bit 1-0 edg1stat: edge 1 status bit 1 = edge 1 has occurred 0 = edge 1 has not occurred
pic18f97j94 family ds30575a-page 512 ? 2012 microchip technology inc. 26.2 ctmu operation the ctmu works by using a fixed current source to charge a circuit. the type of circuit depends on the type of measurement being made. in the case of charge measurement, the current is fixed and the amount of time the current is applied to the cir- cuit is fixed. the amount of voltage read by the a/d becomes a measurement of the circuit?s capacitance. in the case of time measurement, the current, as well as the capacitance of the circuit, is fixed. in this case, the voltage read by the a/d is representative of the amount of time elapsed from the time the current source starts and stops charging the circuit. if the ctmu is being used as a time delay, both capaci- tance and current source are fixed, as well as the voltage supplied to the comparator circuit. the delay of a signal is determined by the amount of time it takes the voltage to charge to the comparator threshold voltage. 26.2.1 theory of operation the operation of the ctmu is based on the equation for charge: more simply, the amount of charge measured in coulombs in a circuit is defined as current in amperes ( i ), multiplied by the amount of time in seconds that the current flows ( t ). charge is also defined as the capaci- tance in farads ( c ), multiplied by the voltage of the circuit ( v ). it follows that: the ctmu module provides a constant, known current source. the a/d converter is used to measure ( v ) in the equation, leaving two unknowns: capacitance ( c ) and time ( t ). the above equation can be used to calcu- late capacitance or time, by either the relationship using the known fixed capacitance of the circuit: or by: using a fixed time that the current source is applied to the circuit. 26.2.2 current source at the heart of the ctmu is a precision current source, designed to provide a constant reference for measure- ments. the level of current is user-selectable across three ranges, or a total of two orders of magnitude, with the ability to trim the output in 2% increments (nominal). the current range is selected by the irng<1:0> bits (ctmucon1<1:0>), with a value of ? 01 ? representing the lowest range. current trim is provided by the itrim<5:0> bits (ctmucon1<7:2>). these six bits allow trimming of the current source, in steps of approximately 2% per step. half of the range adjusts the current source posi- tively and the other half reduces the current source. a value of ? 000000 ? is the neutral position (no change). a value of ? 100001 ? is the maximum negative adjustment (approximately -62%) and ? 011111 ? is the maximum positive adjustment (approximately +62%). 26.2.3 edge selection and control ctmu measurements are controlled by edge events occurring on the module?s two input channels. each chan- nel, referred to as edge 1 and edge 2, can be configured to receive input pulses from one of the edge input pins (cted1 and cted2) or ccpx special event triggers (ccp1 and ccp2). the input channels are level-sensitive, responding to the instantaneous level on the channel rather than a transition between levels. the inputs are selected using the edg1selx (ctmucon2<5:2>) and edg2selx (ctmucon3<5:2>) bit pairs. in addition to source, each channel can be config- ured for event polarity using the edge2pol (ctmucon2<6>) and edge1pol (ctmucon3<6> bits. the input channels can also be filtered for an edge event sequence (edge 1 occurring before edge 2) by setting the edgseqen bit (ctmucon<2>). 26.2.4 edge status the ctmucon3 register also contains two edge status bits: edg2stat and edg1stat (ctmucon3<1:0>). their primary function is to show if an edge response has occurred on the corresponding channel. the ctmu automatically sets a particular bit when an edge response is detected on its channel. the level-sensitive nature of the input channels also means that the status bits become set immediately if the channel?s configuration is changed and matches the channel?s current state. the module uses the edge status bits to control the current source output to external analog modules (such as the a/d converter). current is only supplied to exter- nal modules when only one (not both) of the status bits is set. current is shut off when both bits are either set or cleared. this allows the ctmu to measure current only during the interval between edges. after both status bits are set, it is necessary to clear them before another measurement is taken. both bits should be cleared simultaneously, if possible, to avoid re-enabling the ctmu current source. in addition to being set by the ctmu hardware, the edge status bits can also be set by software. this per- mits a user application to manually enable or disable the current source. setting either (but not both) of the bits enables the current source. setting or clearing both bits at once disables the source. i = c ? dv dt i ? t = c ? v t = (c ? v)/i c = (i ? t)/v
? 2012 microchip technology inc. ds30575a-page 513 pic18f97j94 family 26.2.5 interrupts the ctmu sets its interrupt flag (pir3<3>) whenever the current source is enabled, then disabled. an inter- rupt is generated only if the corresponding interrupt enable bit (pie3<3>) is also set. if edge sequencing is not enabled (i.e., edge 1 must occur before edge 2), it is necessary to monitor the edge status bits, and determine which edge occurred last and caused the interrupt. 26.3 ctmu module initialization the following sequence is a general guideline used to initialize the ctmu module: 1. select the current source range using the irngx bits (ctmucon1<1:0>). 2. adjust the current source trim using the itrimx bits (ctmucon1<7:2>). 3. configure the edge input sources for edge 1 and edge 2 by setting the edg1selx and edg2selx bits (ctmucon3<5:2> and ctmucon2<5:2>, respectively). 4. configure the input polarities for the edge inputs using the edg1pol and edg2pol bits (ctmucon3<6> and ctmucon2<6>). the default configuration is for negative edge polarity (high-to-low transitions). 5. enable edge sequencing using the edgseqen bit (ctmucon<2>). by default, edge sequencing is disabled. 6. select the operating mode (measurement or time delay) with the tgen bit (ctmucon<4>). the default mode is time/capacitance measurement mode. 7. configure the module to automatically trigger an a/d conversion when the second edge event has occurred using the cttrig bit (ctmucon<0>). the conversion trigger is disabled by default. 8. discharge the connected circuit by setting the idissen bit (ctmucon<1>). 9. after waiting a sufficient time for the circuit to discharge, clear the idissen bit. 10. disable the module by clearing the ctmuen bit (ctmucon<7>). 11. clear the edge status bits, edg2stat and edg1stat (ctmucon3<1:0>). both bits should be cleared simultaneously, if possible, to avoid re-enabling the ctmu current source. 12. enable both edge inputs by setting the edgen bit (ctmucon<3>). 13. enable the module by setting the ctmuen bit. depending on the type of measurement or pulse generation being performed, one or more additional modules may also need to be initialized and configured with the ctmu module: ? edge source generation: in addition to the external edge input pins, ccp1/ccp2 special event triggers can be used as edge sources for the ctmu. ? capacitance or time measurement: the ctmu module uses the a/d converter to measure the voltage across a capacitor that is connected to one of the analog input channels. ? pulse generation: when generating system clock independent, output pulses, the ctmu module uses comparator 2 and the associated comparator voltage reference. 26.4 calibrating the ctmu module the ctmu requires calibration for precise measure- ments of capacitance and time, as well as for accurate time delay. if the application only requires measurement of a relative change in capacitance or time, calibration is usually not necessary. an example of a less precise application is a capacitive touch switch, in which the touch circuit has a baseline capacitance and the added capacitance of the human body changes the overall capacitance of a circuit. if actual capacitance or time measurement is required, two hardware calibrations must take place: ? the current source needs calibration to set it to a precise current. ? the circuit being measured needs calibration to measure or nullify any capacitance other than that to be measured. 26.4.1 current source calibration the current source on board the ctmu module has a range of 62% nominal for each of three current ranges. for precise measurements, it is possible to measure and adjust this current source by placing a high-precision resistor, r cal , onto an unused analog channel. an example circuit is shown in figure 26-2 . to measure the current source: 1. initialize the a/d converter. 2. initialize the ctmu. 3. enable the current source by setting edg1stat (ctmucon3<0>). 4. issue time delay for voltage across r cal to stabilize and the a/d sample-and-hold (s/h) capacitor to charge. 5. perform the a/d conversion. 6. calculate the current source current using i=v/r cal , where r cal is a high-precision resistance and v is measured by performing an a/d conversion.
pic18f97j94 family ds30575a-page 514 ? 2012 microchip technology inc. the ctmu current source may be trimmed with the itrimx bits in ctmucon1, using an iterative process to get the exact current desired. alternatively, the nom- inal value without adjustment may be used. that value may be stored by software for use in all subsequent capacitive or time measurements. to calculate the optimal value for r cal , the nominal current must be chosen. for example, if the a/d converter reference voltage is 3.3v, use 70% of full scale (or 2.31v) as the desired approximate voltage to be read by the a/d converter. if the range of the ctmu current source is selected to be 0.55 ? a, the resistor value needed is calculated as r cal = 2.31v/0.55 ? a , for a value of 4.2 m ? . similarly, if the current source is chosen to be 5.5 ? a, r cal would be 420,000 ? , and 42,000 ? if the current source is set to 55 ? a. figure 26-2: ctmu current source calibration circuit a value of 70% of full-scale voltage is chosen to make sure that the a/d converter is in a range that is well above the noise floor. if an exact current is chosen to incorporate the trimming bits from ctmucon1, the resistor value of r cal may need to be adjusted accord- ingly. r cal also may be adjusted to allow for available resistor values. r cal should be of the highest precision available in light of the precision needed for the circuit that the ctmu will be measuring. a recommended minimum would be 0.1% tolerance. the following examples show a typical method for performing a ctmu current calibration. ? example 26-1 demonstrates how to initialize the a/d converter and the ctmu. this routine is typical for applications using both modules. ? example 26-2 demonstrates one method for the actual calibration routine. this method manually triggers the a/d converter to demonstrate the entire step-wise process. it is also possible to automatically trigger the conversion by setting the ctmu?s cttrig bit (ctmucon<0>). a/d converter ctmu anx r cal current source a/d trigger mux a/d pic18f97j94
? 2012 microchip technology inc. ds30575a-page 515 pic18f97j94 family example 26-1: setup for ctmu calibration routines #include "p18cxxx.h" /**************************************************************************/ /*setup ctmu *****************************************************************/ /**************************************************************************/ void setup(void) { //ctmucon - ctmu control register ctmucon = 0x00; //make sure ctmu is disabled ctmucon3 = 0x90; //ctmu continues to run when emulator is stopped,ctmu continues //to run in idle mode,time generation mode disabled, edges are blocked //no edge sequence order, analog current source not grounded, trigger //output disabled, edge2 polarity = positive level, edge2 source = //source 0, edge1 polarity = positive level, edge1 source = source 0, // set edge status bits to zero //ctmucon1 - ctmu current control register ctmucon1 = 0x01; //0.55ua, nominal - no adjustment /**************************************************************************/ //setup ad converter; /**************************************************************************/ trisbbits.trisb0=0; trisabits.trisa2=1; //set channel 2 as an input ancon1bits.ansel2=1; // configured an2 as an analog channel adcon1hbits.form=0b00; // result format 1= right justified adcon1lbits.ssrc=0b0111; adcon3hbits.samc=0b00111; // acquisition time 7 = 20tad 2 = 4tad 1=2tad adcon3lbits.adcs=0x3f; // clock conversion bits 6= fosc/64 2=fosc/32 // adcon1 adcon2hbits.pvcfg=0b00; // vref+ = avdd adcon2hbits.nvcfg0=0; // vref- = avss adchs0lbits.chona=0b000; adchs0lbits.chosa=0b00010; // select adc channel adcon1hbits.adon=1; // turn on adc }
pic18f97j94 family ds30575a-page 516 ? 2012 microchip technology inc. example 26-2: ctmu current calibration routine #include "p18cxxx.h" #define count 500 //@ 8mhz = 125us. #define delay for(i=0;i ? 2012 microchip technology inc. ds30575a-page 517 pic18f97j94 family 26.4.2 capacitance calibration there is a small amount of capacitance from the inter- nal a/d converter sample capacitor, as well as stray capacitance from the circuit board traces and pads that affect the precision of capacitance measurements. a measurement of the stray capacitance can be taken by making sure the desired capacitance to be measured has been removed. after removing the capacitance to be measured: 1. initialize the a/d converter and the ctmu. 2. set edg1stat (= 1 ). 3. wait for a fixed delay of time, t . 4. clear edg1stat. 5. perform an a/d conversion. 6. calculate the stray and a/d sample capacitances: where: ? i is known from the current source measurement step ? t is a fixed delay ? v is measured by performing an a/d conversion this measured value is then stored and used for calculations of time measurement or subtracted for capacitance measurement. for calibration, it is expected that the capacitance of c stray + c ad is approximately known; c ad is approximately 4 pf. an iterative process may be required to adjust the time, t , that the circuit is charged to obtain a reasonable volt- age reading from the a/d converter. the value of t may be determined by setting c offset to a theoretical value and solving for t . for example, if c stray is theoretically calculated to be 11 pf, and v is expected to be 70% of v dd or 2.31v, t would be: or 63 ? s. see example 26-3 for a typical routine for ctmu capacitance calibration. c offset = c stray + c ad = (i ? t)/v (4 pf + 11 pf) ? 2.31v/0.55 ma
pic18f97j94 family ds30575a-page 518 ? 2012 microchip technology inc. example 26-3: ctmu capacitance calibration routine #include "p18cxxx.h" #define count 25 //@ 8mhz intfrc = 62.5 us. #define etime count*2.5 //time in us #define delay for(i=0;i ? 2012 microchip technology inc. ds30575a-page 519 pic18f97j94 family 26.5 measuring capacitance with the ctmu there are two ways to measure capacitance with the ctmu. the absolute method measures the actual capacitance value. the relative method only measures for any change in the capacitance. 26.5.1 absolute capacitance measurement for absolute capacitance measurements, both the current and capacitance calibration steps found in section 26.4 ?calibrating the ctmu module? should be followed. to perform these measurements: 1. initialize the a/d converter. 2. initialize the ctmu. 3. set edg1stat. 4. wait for a fixed delay, t . 5. clear edg1stat. 6. perform an a/d conversion. 7. calculate the total capacitance, c total = (i * t)/v , where: ? i is known from the current source measurement step ( section 26.4.1 ?current source calibration? ) ? t is a fixed delay ? v is measured by performing an a/d conversion 8. subtract the stray and a/d capacitance ( c offset from section 26.4.2 ?capacitance calibration? ) from c total to determine the measured capacitance. 26.5.2 capacitive touch sense using relative charge measurement not all applications require precise capacitance measurements. when detecting a valid press of a capacitance-based switch, only a relative change of capacitance needs to be detected. in such an application when the switch is open (or not touched), the total capacitance is the capacitance of the combination of the board traces, the a/d converter and other elements. a larger voltage will be measured by the a/d converter. when the switch is closed (or touched), the total capacitance is larger due to the addition of the capacitance of the human body to the above listed capacitances and a smaller voltage will be measured by the a/d converter. to detect capacitance changes simply: 1. initialize the a/d converter and the ctmu. 2. set edg1stat. 3. wait for a fixed delay. 4. clear edg1stat. 5. perform an a/d conversion. the voltage measured by performing the a/d conver- sion is an indication of the relative capacitance. in this case, no calibration of the current source or circuit capacitance measurement is needed. (for a sample software routine for a capacitive touch switch, see example 26-4 .)
pic18f97j94 family ds30575a-page 520 ? 2012 microchip technology inc. example 26-4: ctmu routine for capacitive touch switch #include "p18cxxx.h" #define count 500 //@ 8mhz = 125us. #define delay for(i=0;i opensw - trip + hyst) { switchstate = unpressed; } }
? 2012 microchip technology inc. ds30575a-page 521 pic18f97j94 family 26.6 measuring time with the ctmu module time can be precisely measured after the ratio ( c/i ) is measured from the current and capacitance calibration step. to do that: 1. initialize the a/d converter and the ctmu. 2. set edg1stat. 3. set edg2stat. 4. perform an a/d conversion. 5. calculate the time between edges as t = (c/i) * v , where: ? i is calculated in the current calibration step ( section 26.4.1 ?current source calibration? ) ? c is calculated in the capacitance calibra- tion step ( section 26.4.2 ?capacitance calibration? ) ? v is measured by performing the a/d conversion it is assumed that the time measured is small enough that the capacitance, c ad + c ext , provides a valid voltage to the a/d converter. for the smallest time measurement, always set the a/d channel select bits via adcon1l/h to an unused a/d channel; the corre- sponding pin for which is not connected to any circuit board trace. this minimizes added stray capacitance, keeping the total circuit capacitance close to that of the a/d converter itself (25 pf). to measure longer time intervals, an external capacitor may be connected to an a/d channel and that channel selected whenever making a time measurement. figure 26-3: ctmu typical connections and internal configuration for time measurement pic18f97j94 a/d converter ctmu cted1 cted2 an x a/d voltage edg1 edg2 c ad c ext current source
pic18f97j94 family ds30575a-page 522 ? 2012 microchip technology inc. 26.7 measuring temperature with the ctmu the constant-current source provided by the ctmu module can be used for low-cost temperature measurement by exploiting a basic property of com- mon and inexpensive diodes. an on-chip temperature sense diode is provided on a/d channel 29 to further simplify design and cost. 26.7.1 basic principal we can show that the forward voltage ( v f ) of a p-n junction, such as a diode, is an extension of the equation for the junction?s thermal voltage: where k is the boltzmann constant (1.38 x 10 -23 j k -1 ), t is the absolute junction temperature in kelvin, q is the electron charge (1.6 x 10 -19 c), i f is the forward current applied to the diode and i s is the diode?s characteristic saturation current, which varies between devices. since k and q are physical constants, and i s is a constant for the device, this only leaves t and i f as independent variables. if i f is held constant, it follows from the equa- tion that v f will vary as a function of t . as the natural log term of the equation will always be negative, the temper- ature will be negatively proportional to v f . in other words, as temperature increases, v f decreases. by using the ctmu?s current source to provide a constant i f , it becomes possible to calculate the temperature by measuring the v f across the diode. 26.7.2 implementation to implement this theory, all that is needed is to connect a regular junction diode to one of the micro- controller?s a/d pins ( figure 26-2 ). the a/d channel multiplexer is shared by the ctmu and the a/d. to perform a measurement, the multiplexer is config- ured to select the pin connected to the diode. the ctmu current source is then turned on and an a/d conversion is performed on the channel. as shown in the equivalent circuit diagram in figure 26-4 , the diode is driven by the ctmu at i f . the resulting v f across the diode is measured by the a/d. a code snippet is shown in example 26-5 . figure 26-4: ctmu temperature measurement circuit example 26-5: ctmu routine for temperature measurement using internal diode v f = kt q 1n 1 ? i f i s ) ( pic ? microcontroller a/d converter ctmu current source mux a/d v f v f i f ctmu a/d equivalent circuit simplified block diagram // initialize ctmu ctmuicon = 0x03; ctmuconbits.ctmuen = 1; ctmucon3bits.edg1stat = 1; adcon1hbits.form = 0; // right justified adcon1hbits.mode12 = 0; // 12-bit a/d operation adchs0lbits.chosa = 0x18; // enable adc and connect to internal diode adcon1hbits.adon = 1; // enable adc note: the temperature diode is not calibrated or standardized; the user must calibrate the diode to their application.
? 2012 microchip technology inc. ds30575a-page 523 pic18f97j94 family 26.8 operation during sleep/idle modes 26.8.1 sleep mode when the device enters any sleep mode, the ctmu module current source is always disabled. if the ctmu is performing an operation that depends on the current source when sleep mode is invoked, the operation may not terminate correctly. capacitance and time measurements may return erroneous values. 26.8.2 idle mode the behavior of the ctmu in idle mode is determined by the ctmusidl bit (ctmucon<5>). if ctmusidl is cleared, the module will continue to operate in idle mode. if ctmusidl is set, the module?s current source is disabled when the device enters idle mode. in this case, if the module is performing an operation when idle mode is invoked, the results will be similar to those with sleep mode. 26.9 effects of a reset on ctmu upon reset, all registers of the ctmu are cleared. this disables the ctmu module, turns off its current source and returns all configuration options to their default set- tings. the module needs to be re-initialized following any reset. if the ctmu is in the process of taking a measurement at the time of reset, the measurement will be lost. a partial charge may exist on the circuit that was being measured, which should be properly discharged before the ctmu makes subsequent attempts to take a measurement. the circuit is discharged by setting and clearing the idissen bit (ctmucon<1>) while the a/d converter is connected to the appropriate channel.
pic18f97j94 family ds30575a-page 524 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 525 pic18f97j94 family 27.0 universal serial bus (usb) this section describes the details of the usb peripheral. because of the very specific nature of the module, some knowledge of usb is expected. some high-level usb information is provided in section 27.9 ?overview of usb? only for application design reference. designers are encouraged to refer to the official specification published by the usb implementers forum (usb-if) for the latest information. usb specification revision 2.0 is the most current specification at the time of publication of this document. 27.1 overview of the usb peripheral pic18f97j94 family devices contain a full-speed and low-speed, compatible usb serial interface engine (sie) that allows fast communication between any usb host and the pic ? mcu. the sie can be interfaced directly to the usb, utilizing the internal transceiver. some special hardware features have been included to improve performance. dual access port memory in the device?s data memory space (usb ram) has been supplied to share direct memory access (dma) between the microcontroller core and the sie. buffer descriptors are also provided, allowing users to freely program endpoint memory usage within the usb ram space. figure 27-1 provides a general overview of the usb peripheral and its features. figure 27-1: usb peripheral and options 3.8-kbyte usb ram usb sie usb control and transceiver p p d+ d- internal pull-ups external 3.3v supply fsen upuen utrdis usb clock from the oscillator module optional external pull-ups (1) (low (full usb bus fs speed) speed) note 1: the internal pull-up resistors should be disabled (upuen = 0 ) if external pull-up resistors are used. configuration v usb 3 v 3 pic18f97j94
pic18f97j94 family ds30575a-page 526 ? 2012 microchip technology inc. 27.2 usb status and control the operation of the usb module is configured and managed through three control registers. in addition, a total of 22 registers are used to manage the actual usb transactions. the registers are: ? usb control register (ucon) ? usb configuration register (ucfg) ? usb transfer status register (ustat) ? usb device address register (uaddr) ? frame number registers (ufrmh:ufrml) ? endpoint enable registers 0 through 15 (uepn) 27.2.1 usb control register (ucon) the usb control register ( register 27-1 ) contains bits needed to control the module behavior during transfers. the register contains bits that control the following: ? main usb peripheral enable ? ping-pong buffer pointer reset ? control of the suspend mode ? packet transfer disable in addition, the usb control register contains a status bit, se0 (ucon<5>), which is used to indicate the occurrence of a single-ended zero on the bus. when the usb module is enabled, this bit should be monitored to determine whether the differential data lines have come out of a single-ended zero condition. this helps to differentiate the initial power-up state from the usb reset signal. the overall operation of the usb module is controlled by the usben bit (ucon<3>). setting this bit activates the module and resets all of the ppbi bits in the buffer descriptor table (bdt) to ? 0 ?. this bit also activates the internal pull-up resistors if they are enabled. thus, this bit can be used as a soft attach/detach to the usb. although all status and control bits are ignored when this bit is clear, the module needs to be fully preconfig- ured prior to setting this bit. the usb clock source should have been already configured for the correct frequency and running. if the pll is being used, it should be enabled for at least 2 ms (enough time for the pll to lock) before attempting to set the usben bit. note: when disabling the usb module, make sure the suspnd bit (ucon<1>) is clear prior to clearing the usben bit. clearing the usben bit when the module is in the suspended state may prevent the module from fully powering down
? 2012 microchip technology inc. ds30575a-page 527 pic18f97j94 family register 27-1: ucon: usb control register u-0 r/w-0 r-x r/c-0 r/w-0 r/w-0 r/w-0 u-0 ? ppbrst ( 2 ) se0 pktdis usben ( 1 ) resume suspnd ? bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 ppbrst: ping-pong buffers reset bit ( 2 ) 1 = reset all ping-pong buffer pointers to the even buffer descriptor (bd) banks 0 = ping-pong buffer pointers are not being reset bit 5 se0: live single-ended zero flag bit 1 = single-ended zero is active on the usb bus 0 = no single-ended zero is detected bit 4 pktdis: packet transfer disable bit 1 = sie token and packet processing are disabled, automatically set when a setup token is received 0 = sie token and packet processing are enabled bit 3 usben: usb module enable bit ( 1 ) 1 = usb module and supporting circuitry are enabled (device attached) 0 = usb module and supporting circuitry are disabled (device detached) bit 2 resume: resume signaling enable bit 1 = resume signaling is activated 0 = resume signaling is disabled bit 1 suspnd: suspend usb bit 1 = usb module and supporting circuitry are in power conserve mode, sie clock is inactive 0 = usb module and supporting circuitry are in normal operation, sie is clocked at the configured rate bit 0 unimplemented : read as ? 0 ? note 1: make sure the usb clock source is correctly configured before setting this bit. 2: there should be at least four cycles of delay between the setting and ppbrst.
pic18f97j94 family ds30575a-page 528 ? 2012 microchip technology inc. the ppbrst bit (ucon<6>) controls the reset status when double-buffering mode (ping-pong buffering) is used. when the ppbrst bit is set, all ping-pong buffer pointers are set to the even buffers. ppbrst has to be cleared by firmware. this bit is ignored in buffering modes not using ping-pong buffering. the pktdis bit (ucon<4>) is a flag indicating that the sie has disabled packet transmission and reception. this bit is set by the sie when a setup token is received to allow setup processing. this bit cannot be set by the microcontroller, only cleared; clearing it allows the sie to continue transmission and/or reception. any pending events within the buffer descriptor table (bdt) will still be available, indicated within the ustat register?s fifo buffer. the resume bit (ucon<2>) allows the peripheral to perform a remote wake-up by executing resume signaling. to generate a valid remote wake-up, firmware must set resume for 10 ms and then clear the bit. for more information on resume signaling, see sections 7.1.7.5, 11.4.4 and 11.9 in the ? usb 2.0 specification ?. the suspnd bit (ucon<1>) places the module and supporting circuitry in a low-power mode. the input clock to the sie is also disabled. this bit should be set by the software in response to an idleif interrupt. it should be reset by the microcontroller firmware after an actvif interrupt is observed. when this bit is active, the device remains attached to the bus but the transceiver outputs remain idle. the voltage on the v usb 3 v 3 pin may vary depending on the value of this bit. setting this bit before a idleif request will result in unpredictable bus behavior. 27.2.2 usb configuration register (ucfg) prior to communicating over usb, the module?s associated internal and/or external hardware must be configured. most of the configuration is performed with the ucfg register ( register 27-2 ).the ufcg register contains most of the bits that control the system-level behavior of the usb module. these include: ? bus speed (full speed versus low speed) ? on-chip pull-up resistor enable ? on-chip transceiver enable ? ping-pong buffer usage the ucfg register also contains two bits, which aid in module testing, debugging and usb certifications. these bits control output enable state monitoring and eye pattern generation. 27.2.2.1 internal transceiver the usb peripheral has a built-in, ? usb 2.0 specifica- tion ?, full-speed and low-speed capable transceiver, internally connected to the sie. this feature is useful for low-cost, single chip applications. the utrdis bit (ucfg<3>) controls the transceiver; it is enabled by default (utrdis = 0 ). the fsen bit (ucfg<2>) controls the transceiver speed; setting this bit enables full-speed operation. the on-chip usb pull-up resistors are controlled by the upuen bit (ucfg<4>). they can only be selected when the on-chip transceiver is enabled. the internal usb transceiver obtains power from the v usb 3 v 3 pin. in order to meet usb signalling level specifications, v usb 3 v 3 must be supplied with a voltage source between 3.0v and 3.6v. the best electrical sig- nal quality is obtained when a 3.3v supply is used and locally bypassed with a high quality ceramic capacitor (ex: 0.1 ? f). the capacitor should be placed as close as possible to the v usb 3 v 3 and v ss pins. v usb 3 v 3 should always be maintained ? v dd . if the usb module is not used, but rc4 or rc5 are used as general purpose inputs, v usb 3 v 3 should still be con- nected to a power source (such as v dd ). the input thresholds for the rc4 and rc5 pins are dependent upon the v usb 3 v 3 supply level. the d+ and d- signal lines can be routed directly to their respective pins on the usb connector or cable (for hard-wired applications). no additional resistors, capacitors or magnetic components are required, as the d+ and d- drivers have controlled slew rate and output impedance, intended to match with the characteristic impedance of the usb cable. in order to achieve optimum usb signal quality, the d+ and d- traces between the microcontroller and usb connector (or cable) should be less than 19 cm long. both traces should be equal in length and they should be routed parallel to each other. ideally, these traces should be designed to have a characteristic impedance matching that of the usb cable. note: while in suspend mode, a typical bus- powered usb device is limited to 2.5 ma of current. this is the complete current which may be drawn by the pic mcu device and its supporting circuitry. care should be taken to assure minimum current draw when the device enters suspend mode. note: the usb speed, transceiver and pull-up should only be configured during the module setup phase. it is not recom- mended to switch these settings while the module is enabled.
? 2012 microchip technology inc. ds30575a-page 529 pic18f97j94 family register 27-2: ucfg: usb configuration register r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 uteye uoemon ? upuen ( 1 , 2 ) utrdis ( 1 , 3 ) fsen ( 1 ) ppb1 ppb0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 uteye: usb eye pattern test enable bit 1 = eye pattern test is enabled 0 = eye pattern test is disabled bit 6 uoemon: usb oe monitor enable bit 1 =uoe signal is active, indicating intervals during which the d+/d- lines are driving 0 =uoe signal is inactive bit 5 unimplemented: read as ? 0 ? bit 4 upuen: usb on-chip pull-up enable bit ( 1 , 2 ) 1 = on-chip pull-up is enabled (pull-up on d+ with fsen = 1 or d- with fsen = 0 ) 0 = on-chip pull-up is disabled bit 3 utrdis: on-chip transceiver disable bit ( 1 , 3 ) 1 = on-chip transceiver is disabled 0 = on-chip transceiver is active bit 2 fsen: full-speed enable bit ( 1 ) 1 = full-speed device: controls transceiver edge rates; requires input clock at 48 mhz 0 = low-speed device: controls transceiver edge rates; requires input clock at 6 mhz bit 1-0 ppb<1:0>: ping-pong buffers configuration bits 11 = even/odd ping-pong buffers are enabled for endpoints 1 to 15 10 = even/odd ping-pong buffers are enabled for all endpoints 01 = even/odd ping-pong buffer are enabled for out endpoint 0 00 = even/odd ping-pong buffers are disabled note 1: the upuen, utrdis and fsen bits should never be changed while the usb module is enabled. these values must be preconfigured prior to enabling the module. 2: this bit is only valid when the on-chip transceiver is active (utrdis = 0 ); otherwise, it is ignored. 3: if utrdis is set, the uoe signal will be active, independent of the uoemon bit setting.
pic18f97j94 family ds30575a-page 530 ? 2012 microchip technology inc. 27.2.2.2 internal pull-up resistors the pic18f97j94 family devices have built-in pull-up resistors, designed to meet the requirements for low- speed and full-speed usb. the upuen bit (ucfg<4>) enables the internal pull-ups. figure 27-1 shows the pull-ups and their control. 27.2.2.3 external pull-up resistors external pull-ups may also be used. the v usb 3 v 3 pin may be used to pull up d+ or d-. the pull-up resistor must be 1.5 k ? (5%) as required by the usb specifications. figure 27-2 provides an example of external circuitry. figure 27-2: external circuitry 27.2.2.4 ping-pong buffer configuration the usage of ping-pong buffers is configured using the ppb<1:0> bits. refer to section 27.4.4 ?ping-pong buffering? for a complete explanation of the ping-pong buffers. 27.2.2.5 eye pattern test enable an automatic eye pattern test can be generated by the module when the ucfg<7> bit is set. the eye pattern output will be observable based on module settings, meaning that the user is first responsible for configuring the sie clock settings, pull-up resistor and transceiver mode. in addition, the module has to be enabled. once uteye is set, the module emulates a switch from a receive to transmit state and will start transmitting a j-k-j-k bit sequence (k-j-k-j for full speed). the sequence will be repeated indefinitely while the eye pattern test mode is enabled. note that this bit should never be set while the module is connected to an actual usb system. this test mode is intended for board verification to aid with usb certi- fication tests. it is intended to show a system developer the noise integrity of the usb signals which can be affected by board traces, impedance mismatches and proximity to other system components. it does not properly test the transition from a receive to a transmit state. although the eye pattern is not meant to replace the more complex usb certification test, it should aid during first order system debugging. note: a compliant usb device should never source any current onto the +5v v bus line of the usb cable. additionally, usb devices should not source any current on the d+ and d- data lines whenever the +5v v bus line is less than 1.17v. in order to be usb compliant, applications which are not purely bus-powered should moni- tor the v bus line, and avoid turning on the usb module and the d+ or d- pull-up resistor until v bus is greater than 1.17v. v bus can be connected to and monitored by a 5v tolerant i/o pin, or if a resistive divider is used, by an analog capable pin. pic ? mcu host controller/hub v usb 3 v 3 d+ d- note: the above setting shows a typical connection for a full-speed configuration using an on-chip regulator and an external pull-up resistor. 1.5 k ?
? 2012 microchip technology inc. ds30575a-page 531 pic18f97j94 family 27.2.3 usb status register (ustat) the usb status register reports the transaction status within the sie. when the sie issues a usb transfer complete interrupt, ustat should be read to determine the status of the transfer. ustat contains the transfer endpoint number, direction and ping-pong buffer pointer value (if used). the ustat register is actually a read window into a 4-byte status fifo, maintained by the sie. it allows the microcontroller to process one transfer while the sie processes additional endpoints ( figure 27-3 ). when the sie completes using a buffer for reading or writing data, it updates the ustat register. if another usb transfer is performed before a transaction complete interrupt is serviced, the sie will store the status of the next transfer into the status fifo. clearing the transfer complete flag bit, trnif, causes the sie to advance the fifo. if the next data in the fifo holding register is valid, the sie will reassert the interrupt within 5 t cy of clearing trnif. if no addi- tional data is present, trnif will remain clear; ustat data will no longer be reliable. figure 27-3: ustat fifo note: the data in the usb status register is valid only when the trnif interrupt flag is asserted. note: if an endpoint request is received while the ustat fifo is full, the sie will automatically issue a nak back to the host. data bus ustat from sie 4-byte fifo for ustat clearing trnif advances fifo register 27-3: ustat: usb status register (access f64h) u-0 r-x r-x r-x r-x r-x r-x u-0 ? endp3 endp2 endp1 endp0 dir ppbi ( 1 ) ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-3 endp<3:0>: encoded number of last endpoint activity bits (represents the number of the bdt updated by the last usb transfer) 1111 = endpoint 15 1110 = endpoint 14 . . . 0001 = endpoint 1 0000 = endpoint 0 bit 2 dir: last bd direction indicator bit 1 = the last transaction was an in token 0 = the last transaction was an out or setup token bit 1 ppbi: ping-pong bd pointer indicator bit ( 1 ) 1 = the last transaction was to the odd bd bank 0 = the last transaction was to the even bd bank bit 0 unimplemented: read as ? 0 ? note 1: this bit is only valid for endpoints with available even and odd bd registers.
pic18f97j94 family ds30575a-page 532 ? 2012 microchip technology inc. 27.2.4 usb endpoint control each of the 16 possible bidirectional endpoints has its own independent control register, uepn (where ?n? represents the endpoint number). each register has an identical complement of control bits. register 27-4 provides the prototype. the ephshk bit (uepn<4>) controls handshaking for the endpoint; setting this bit enables usb handshaking. typically, this bit is always set except when using isochronous endpoints. the epcondis bit (uepn<3>) is used to enable or disable usb control operations (setup) through the endpoint. clearing this bit enables setup transac- tions. note that the corresponding epinen and epouten bits must be set to enable in and out transactions. for endpoint 0, this bit should always be cleared since the usb specifications identify endpoint 0 as the default control endpoint. the epouten bit (uepn<2>) is used to enable or disable usb out transactions from the host. setting this bit enables out transactions. similarly, the epinen bit (uepn<1>) enables or disables usb in transactions from the host. the epstall bit (uepn<0>) is used to indicate a stall condition for the endpoint. if a stall is issued on a particular endpoint, the epstall bit for that end- point pair will be set by the sie. this bit remains set until it is cleared through firmware or until the sie is reset. register 27-4: uepn: usb endpoint n co ntrol register (uep0 through uep15) u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? ephshk epcondis epouten epinen epstall bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 ephshk: endpoint handshake enable bit 1 = endpoint handshake is enabled 0 = endpoint handshake is disabled (typically used for isochronous endpoints) bit 3 epcondis: bidirectional endpoint control bit if epouten = 1 and epinen = 1 : 1 = disables endpoint n from control transfers; only in and out transfers are allowed 0 = enables endpoint n for control (setup) transfers; in and out transfers are also allowed bit 2 epouten: endpoint output enable bit 1 = endpoint n output is enabled 0 = endpoint n output is disabled bit 1 epinen: endpoint input enable bit 1 = endpoint n input is enabled 0 = endpoint n input is disabled bit 0 epstall: endpoint stall indicator bit 1 = endpoint n has issued one or more stall packets 0 = endpoint n has not issued any stall packets
? 2012 microchip technology inc. ds30575a-page 533 pic18f97j94 family 27.2.5 usb address register (uaddr) the usb address register contains the unique usb address that the peripheral will decode when active. uaddr is reset to 00h when a usb reset is received, indicated by urstif, or when a reset is received from the microcontroller. the usb address must be written by the microcontroller during the usb setup phase (enumeration) as part of the microchip usb firmware support. 27.2.6 usb frame number registers (ufrmh:ufrml) the frame number registers contain the 11-bit frame number. the low-order byte is contained in ufrml, while the three high-order bits are contained in ufrmh. the register pair is updated with the current frame number whenever a sof token is received. for the microcontroller, these registers are read-only. the frame number registers are primarily used for isochronous transfers. the contents of the ufrmh and ufrml registers are only valid when the 48 mhz sie clock is active (i.e., contents are inaccurate when suspnd (ucon<1>) bit = 1 ). 27.3 usb ram usb data moves between the microcontroller core and the sie through a memory space, known as the usb ram. this is a special dual access memory that is mapped into the normal data memory space in banks 0 through 14 (00h to ebfh), for a total of 3.8 kbytes ( figure 27-4 ). bank 13 (d00h through dffh) is used specifically for endpoint buffer control, while banks 0 through 12 and bank 14 are available for usb data. depending on the type of buffering being used, all but 8 bytes of bank 13 may also be available for use as usb buffer space. although usb ram is available to the microcontroller as data memory, the sections that are being accessed by the sie should not be accessed by the micro- controller. a semaphore mechanism is used to determine the access to a particular buffer at any given time. this is discussed in section 27.4.1.1 ?buffer ownership? . figure 27-4: implementation of usb ram in data memory space d00h dffh e00h usb data or buffer descriptors, usb data or user data user data cffh 000h fffh banks 0 (usb ram) to 14 access ram 060h 05fh ec0h ebfh sfrs
pic18f97j94 family ds30575a-page 534 ? 2012 microchip technology inc. 27.4 buffer descriptors and the buffer descriptor table the registers in bank 13 are used specifically for end- point buffer control in a structure known as the buffer descriptor table (bdt). this provides a flexible method for users to construct and control endpoint buffers of various lengths and configuration. the bdt is composed of buffer descriptors (bd) which are used to define and control the actual buffers in the usb ram space. each bd, in turn, consists of four registers, where n represents one of the 64 possible bds (range of 0 to 63): ? bdnstat: bd status register ? bdncnt: bd byte count register ? bdnadrl: bd address low register ? bdnadrh: bd address high register bds always occur as a four-byte block in the sequence, bdnstat:bdncnt:bdnadrl:bdnadrh. the address of bdnstat is always an offset of (4n ? 1, in hexa- decimal) from d00h, with n being the buffer descriptor number. depending on the buffering configuration used ( section 27.4.4 ?ping-pong buffering? ), there are up to 32, 33 or 64 sets of buffer descriptors. at a minimum, the bdt must be at least 8 bytes long. this is because the usb specification mandates that every device must have endpoint 0 with both input and output for ini- tial setup. depending on the endpoint and buffering configuration, the bdt can be as long as 256 bytes. although they can be thought of as special function registers, the buffer descriptor status and address registers are not hardware mapped, as conventional microcontroller sfrs in bank 15 are. if the endpoint cor- responding to a particular bd is not enabled, its registers are not used. instead of appearing as unimplemented addresses, however, they appear as available ram. only when an endpoint is enabled by setting the uepn<1> bit does the memory at those addresses become functional as bd registers. as with any address in the data memory space, the bd registers have an indeterminate value on any device reset. figure 27-5 provides an example of a bd for a 64-byte buffer, starting at 500h. a particular set of bd registers is only valid if the corresponding endpoint has been enabled using the uepn register. all bd registers are available in usb ram. the bd for each endpoint should be set up prior to enabling the endpoint. 27.4.1 bd status and configuration buffer descriptors not only define the size of an end- point buffer, but also determine its configuration and control. most of the configuration is done with the bd status register, bdnstat. each bd has its own unique and correspondingly numbered bdnstat register. figure 27-5: example of a buffer descriptor unlike other control registers, the bit configuration for the bdnstat register is context-sensitive. there are two distinct configurations, depending on whether the microcontroller or the usb module is modifying the bd and buffer at a particular time. only three bit definitions are shared between the two. 27.4.1.1 buffer ownership because the buffers and their bds are shared between the cpu and the usb module, a simple semaphore mechanism is used to distinguish which is allowed to update the bd and associated buffers in memory. this is done by using the uown bit (bdnstat<7>) as a semaphore to distinguish which is allowed to update the bd and associated buffers in memory. uown is the only bit that is shared between the two configurations of bdnstat. when uown is clear, the bd entry is ?owned? by the microcontroller core. when the uown bit is set, the bd entry and the buffer memory are ?owned? by the usb peripheral. the core should not modify the bd or its corresponding data buffer during this time. note that the microcontroller core can still read bdnstat while the sie owns the buffer and vice versa. the buffer descriptors have a different meaning based on the source of the register update. prior to placing ownership with the usb peripheral, the user can configure the basic operation of the peripheral through the bdnstat bits. during this time, the byte count and buffer location registers can also be set. when uown is set, the user can no longer depend on the values that were written to the bds. from this point, the sie updates the bds as necessary, overwriting the original bd values. the bdnstat register is updated by the sie with the token pid and the transfer count, bdncnt, is updated. d00h usb data buffer buffer bd0stat bd0cnt bd0adrl bd0adrh d01h d02h d03h 500h 53fh descriptor note: memory regions are not to scale. 40h 00h 05h starting size of block (xxh) registers address contents address
? 2012 microchip technology inc. ds30575a-page 535 pic18f97j94 family the bdnstat byte of the bdt should always be the last byte updated when preparing to arm an endpoint. the sie will clear the uown bit when a transaction has completed. no hardware mechanism exists to block access when the uown bit is set. thus, unexpected behavior can occur if the microcontroller attempts to modify memory when the sie owns it. similarly, reading such memory may produce inaccurate data until the usb peripheral returns ownership to the microcontroller. 27.4.1.2 bdnstat register (cpu mode) when uown = 0 , the microcontroller core owns the bd. at this point, the other seven bits of the register take on control functions. the data toggle sync enable bit, dtsen (bdnstat<3>), controls data toggle parity checking. setting dtsen enables data toggle synchronization by the sie. when enabled, it checks the data packet?s par- ity against the value of dts (bdnstat<6>). if a packet arrives with an incorrect synchronization, the data will essentially be ignored. it will not be written to the usb ram and the usb transfer complete interrupt flag will not be set. the sie will send an ack token back to the host to acknowledge receipt, however. the effects of the dtsen bit on the sie are summarized in table 27-1 . the buffer stall bit, bstall (bdnstat<2>), provides support for control transfers, usually one-time stalls on endpoint 0. it also provides support for the set_feature/clear_feature commands speci- fied in chapter 9 of the usb specification; typically, continuous stalls to any endpoint other than the default control endpoint. the bstall bit enables buffer stalls. setting bstall causes the sie to return a stall token to the host if a received token would use the bd in that location. the epstall bit in the corresponding uepn control register is set and a stall interrupt is generated when a stall is issued to the host. the uown bit remains set and the bds are not changed unless a setup token is received. in this case, the stall condition is cleared and the ownership of the bd is returned to the microcontroller core. the bc<9:8> bits (bdnstat<1:0>) store the two most significant digits of the sie byte count. the lower 8 digits are stored in the corresponding bdncnt register. see section 27.4.2 ?bd byte count? for more information. table 27-1: effect of dtsen bit on odd/even (data0/data1) packet reception out packet from host bdnstat settings device response after receiving packet dtsen dts handshake uown trnif bdnstat and ustat status data0 10 ack 01 updated data1 10 ack 10 not updated data0 11 ack 10 not updated data1 11 ack 01 updated either 0x ack 01 updated either, with error xx nak 10 not updated legend: x = don?t care
pic18f97j94 family ds30575a-page 536 ? 2012 microchip technology inc. register 27-5: bdnstat: buffer descriptor n status register (bd0stat through bd63stat), cpu mode r/w-x r/w-x u-0 u-0 r/w-x r/w-x r/w-x r/w-x uown ( 1 ) dts ( 2 ) ? ( 3 ) ? ( 3 ) dtsen bstall bc9 bc8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 uown: usb own bit ( 1 ) 0 = the microcontroller core owns the bd and its corresponding buffer bit 6 dts: data toggle synchronization bit ( 2 ) 1 = data 1 packet 0 = data 0 packet bit 5-4 unimplemented: these bits should always be programmed to ? 0 ? ( 3 ) bit 3 dtsen: data toggle synchronization enable bit 1 = data toggle synchronization is enabled; data packets with incorrect sync value will be ignored, except for a setup transaction, which is accepted even if the data toggle bits do not match 0 = no data toggle synchronization is performed bit 2 bstall: buffer stall enable bit 1 = buffer stall is enabled; stall handshake issued if a token is received that would use the bd in the given location (uown bit remains set, bd value is unchanged) 0 = buffer stall is disabled bit 1-0 bc<9:8>: byte count 9 and 8 bits the byte count bits represent the number of bytes that will be transmitted for an in token or received during an out token. together with bc<7:0>, the valid byte counts are 0-1023. note 1: this bit must be initialized by the user to the desired value prior to enabling the usb module. 2: this bit is ignored unless dtsen = 1 . 3: if these bits are set, usb communication may not work. hence, these bits should always be maintained as ? 0 ?.
? 2012 microchip technology inc. ds30575a-page 537 pic18f97j94 family 27.4.1.3 bdnstat register (sie mode) when the bd and its buffer are owned by the sie, most of the bits in bdnstat take on a different meaning. the configuration is shown in register 27-6 . once uown is set, any data or control settings previously written there by the user will be overwritten with data from the sie. the bdnstat register is updated by the sie with the token packet identifier (pid) which is stored in bdnstat<5:2>. the transfer count in the correspond- ing bdncnt register is updated. values that overflow the 8-bit register carry over to the two most significant digits of the count, stored in bdnstat<1:0>. 27.4.2 bd byte count the byte count represents the total number of bytes that will be transmitted during an in transfer. after an in transfer, the sie will return the number of bytes sent to the host. for an out transfer, the byte count represents the maximum number of bytes that can be received and stored in usb ram. after an out transfer, the sie will return the actual number of bytes received. if the number of bytes received exceeds the corresponding byte count, the data packet will be rejected and a nak handshake will be generated. when this happens, the byte count will not be updated. the 10-bit byte count is distributed over two registers. the lower 8 bits of the count reside in the bdncnt register; the upper two bits reside in bdnstat<1:0>. this represents a valid byte range of 0 to 1023. 27.4.3 bd address validation the bd address register pair contains the starting ram address location for the corresponding endpoint buffer. no mechanism is available in hardware to validate the bd address. if the value of the bd address does not point to an address in the usb ram, or if it points to an address within another endpoint?s buffer, data is likely to be lost or overwritten. similarly, overlapping a receive buffer (out endpoint) with a bd location in use can yield unexpected results. when developing usb applications, the user may want to consider the inclusion of software-based address validation in their code. register 27-6: bdnstat: buffer descriptor n status register (bd0stat through bd63stat), sie mode (data returned by the sie to the mcu) r/w-x r-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x uown r pid3 pid2 pid1 pid0 bc9 bc8 bit 7 bit 0 legend: r = reserved bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 uown: usb own bit 1 = the sie owns the bd and its corresponding buffer bit 6 reserved: not written by the sie bit 5-2 pid<3:0>: packet identifier bits the received token pid value of the last transfer (in, out or setup transactions only). bit 1-0 bc<9:8>: byte count 9 and 8 bits these bits are updated by the sie to reflect the actual number of bytes received on an out transfer and the actual number of bytes transmitted on an in transfer.
pic18f97j94 family ds30575a-page 538 ? 2012 microchip technology inc. 27.4.4 ping-pong buffering an endpoint is defined to have a ping-pong buffer when it has two sets of bd entries: one set for an even transfer and one set for an odd transfer. this allows the cpu to process one bd while the sie is processing the other bd. double-buffering bds in this way allows for maximum throughput to/from the usb. the usb module supports four modes of operation: ? no ping-pong support ? ping-pong buffer support for out endpoint 0 only ? ping-pong buffer support for all endpoints ? ping-pong buffer support for all other endpoints except endpoint 0 the ping-pong buffer settings are configured using the ppb<1:0> bits in the ucfg register. the usb module keeps track of the ping-pong pointer individually for each endpoint. all pointers are initially reset to the even bd when the module is enabled. after the completion of a transaction (uown cleared by the sie), the pointer is toggled to the odd bd. after the completion of the next transaction, the pointer is toggled back to the even bd and so on. the even/odd status of the last transaction is stored in the ppbi bit of the ustat register. the user can reset all ping-pong pointers to even using the ppbrst bit. figure 27-6 shows the four different modes of operation and how usb ram is filled with the bds. bds have a fixed relationship to a particular endpoint, depending on the buffering configuration. tab l e 2 7- 2 provides the mapping of bds to endpoints. this relationship also means that gaps may occur in the bdt if endpoints are not enabled contiguously. this, theoretically, means that the bds for disabled endpoints could be used as buffer space. in practice, users should avoid using such spaces in the bdt unless a method of validating bd addresses is implemented. figure 27-6: buffer descriptor t able mapping for buffering modes ep1 in even ep1 out even ep1 out odd ep1 in odd descriptor descriptor descriptor descriptor ep1 in ep15 in ep1 out ep0 out ppb<1:0> = 00 ep0 in ep1 in no ping-pong ep15 in ep0 in ep0 out even ppb<1:0> = 01 ep0 out odd ep1 out ping-pong buffer ep15 in odd ep0 in even ep0 out even ppb<1:0> = 10 ep0 out odd ep0 in odd ping-pong buffers descriptor descriptor descriptor descriptor descriptor descriptor descriptor descriptor descriptor descriptor descriptor descriptor d00h dffh dffh dffh d00h d00h d7fh d83h available as data ram available as data ram maximum memory used: 128 bytes maximum bds: 32 (bd0 to bd31) maximum memory used: 132 bytes maximum bds: 33 (bd0 to bd32) maximum memory used: 256 bytes maximum bds: 64 (bd0 to bd63) note: memory area is not shown to scale. descriptor descriptor descriptor descriptor buffers on ep0 out on all eps ep1 in even ep1 out even ep1 out odd ep1 in odd descriptor descriptor descriptor descriptor ep15 in odd ep0 out ppb<1:0> = 11 ep0 in ping-pong buffers descriptor descriptor descriptor dffh d00h maximum memory used: 248 bytes maximum bds: 62 (bd0 to bd61) on all other eps except ep0 available as data ram df7h
? 2012 microchip technology inc. ds30575a-page 539 pic18f97j94 family table 27-2: assignment of buffer descriptors for the different buffering modes table 27-3: summary of usb buffer descriptor table registers endpoint bds assigned to endpoint mode 0 (no ping-pong) mode 1 (ping-pong on ep0 out) mode 2 (ping-pong on all eps) mode 3 (ping-pong on all other eps, except ep0) out in out in out in out in 0 0 1 0 (e), 1 (o) 2 0 (e), 1 (o) 2 (e), 3 (o) 0 1 1 2 3 3 4 4 (e), 5 (o) 6 (e), 7 (o) 2 (e), 3 (o) 4 (e), 5 (o) 2 4 5 5 6 8 (e), 9 (o) 10 (e), 11 (o) 6 (e), 7 (o) 8 (e), 9 (o) 3 6 7 7 8 12 (e), 13 (o) 14 (e), 15 (o) 10 (e), 11 (o) 12 (e), 13 (o) 4 8 9 9 10 16 (e), 17 (o) 18 (e), 19 (o) 14 (e), 15 (o) 16 (e), 17 (o) 5 10 11 11 12 20 (e), 21 (o) 22 (e), 23 (o) 18 (e), 19 (o) 20 (e), 21 (o) 6 12 13 13 14 24 (e), 25 (o) 26 (e), 27 (o) 22 (e), 23 (o) 24 (e), 25 (o) 7 14 15 15 16 28 (e), 29 (o) 30 (e), 31 (o) 26 (e), 27 (o) 28 (e), 29 (o) 8 16 17 17 18 32 (e), 33 (o) 34 (e), 35 (o) 30 (e), 31 (o) 32 (e), 33 (o) 9 18 19 19 20 36 (e), 37 (o) 38 (e), 39 (o) 34 (e), 35 (o) 36 (e), 37 (o) 10 20 21 21 22 40 (e), 41 (o) 42 (e), 43 (o) 38 (e), 39 (o) 40 (e), 41 (o) 11 22 23 23 24 44 (e), 45 (o) 46 (e), 47 (o) 42 (e), 43 (o) 44 (e), 45 (o) 12 24 25 25 26 48 (e), 49 (o) 50 (e), 51 (o) 46 (e), 47 (o) 48 (e), 49 (o) 13 26 27 27 28 52 (e), 53 (o) 54 (e), 55 (o) 50 (e), 51 (o) 52 (e), 53 (o) 14 28 29 29 30 56 (e), 57 (o) 58 (e), 59 (o) 54 (e), 55 (o) 56 (e), 57 (o) 15 30 31 31 32 60 (e), 61 (o) 62 (e), 63 (o) 58 (e), 59 (o) 60 (e), 61 (o) legend: (e) = even transaction buffer, (o) = odd transaction buffer name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bdnstat ( 1 ) uown dts ( 4 ) pid3 ( 2 ) pid2 ( 2 ) pid1 ( 2 ) dtsen ( 3 ) pid0 ( 2 ) bstall ( 3 ) bc9 bc8 bdncnt ( 1 ) byte count bdnadrl ( 1 ) buffer address low bdnadrh ( 1 ) buffer address high note 1: for buffer descriptor registers, n may have a value of 0 to 63. for the sake of brevity, all 64 registers are shown as one generic prototype. all registers have indeterminate reset values ( xxxx xxxx ). 2: bits 5 through 2 of the bdnstat register are used by the sie to return pid<3:0> values once the register is turned over to the sie (uown bit is set). once the registers have been under sie control, the values written for dtsen and bstall are no longer valid. 3: prior to turning the buffer descriptor over to the sie (uown bit is cleared), bits 5 through 2 of the bdnstat register are used to configure the dtsen and bstall settings. 4: this bit is ignored unless dtsen = 1 .
pic18f97j94 family ds30575a-page 540 ? 2012 microchip technology inc. 27.5 usb interrupts the usb module can generate multiple interrupt condi- tions. to accommodate all of these interrupt sources, the module is provided with its own interrupt logic struc- ture, similar to that of the microcontroller. usb interrupts are enabled with one set of control registers and trapped with a separate set of flag registers. all sources are funneled into a single usb oscillator fail interrupt flag bit, usbif (pir2<4>), in the microcontroller?s interrupt logic. figure 27-7 provides the interrupt logic for the usb module. there are two layers of interrupt registers in the usb module. the top level consists of overall usb status interrupts; these are enabled and flagged in the uie and uir registers, respectively. the second level consists of usb error conditions, which are enabled and flagged in the ueir and ueie registers. an interrupt condition in any of these triggers a usb error interrupt flag (uerrif) in the top level. interrupts may be used to trap routine events in a usb transaction. figure 27-8 provides some common events within a usb frame and its corresponding interrupts. figure 27-7: usb interrupt logic funnel figure 27-8: example of a usb transaction and interrupt events btsef btsee btoef btoee dfn8ef dfn8ee crc16ef crc16ee crc5ef crc5ee pidef pidee sofif sofie trnif trnie idleif idleie stallif stallie actvif actvie urstif urstie uerrif uerrie usbif second level usb interrupts (usb error conditions ueir (flag) and ueie (enable) registers top level usb interrupts (usb status interrupts uir (flag) and uie (enable) registers usb reset sof reset setup data status sof setup token data ack out token empty data ack start-of-frame (sof) in token data ack sofif urstif 1 ms frame differential data from host from host to host from host to host from host from host from host to host transaction control transfer (1) transaction complete note 1: the control transfer shown here is only an example showin g events that can occur for every transaction. typical control transfers will spread across multiple frames. set trnif set trnif set trnif
? 2012 microchip technology inc. ds30575a-page 541 pic18f97j94 family 27.5.1 usb interrupt status register (uir) the usb interrupt status register ( register 27-7 ) con- tains the flag bits for each of the usb status interrupt sources. each of these sources has a corresponding interrupt enable bit in the uie register. all of the usb status flags are ored together to generate the usbif interrupt flag for the microcontroller?s interrupt funnel. once an interrupt bit has been set by the sie, it must be cleared in software by writing a ? 0 ?. the flag bits can also be set in software, which can aid in firmware debugging. when the usb module is in the low-power suspend mode (ucon<1> = 1 ), the sie does not get clocked. when in this state, the sie cannot process packets, and therefore, cannot detect new interrupt conditions other than the activity detect interrupt, actvif. the actvif bit is typically used by usb firmware to detect when the microcontroller should bring the usb module out of the low-power suspend mode (ucon<1> = 0 ). register 27-7: uir: usb interrupt status register (access f62h) u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r/w-0 ? sofif stallif idleif ( 1 ) trnif ( 2 ) actvif ( 3 ) uerrif ( 4 ) urstif bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 sofif: start-of-frame token interrupt bit 1 = a start-of-frame token is received by the sie 0 = no start-of-frame token is received by the sie bit 5 stallif: a stall handshake interrupt bit 1 = a stall handshake was sent by the sie 0 = a stall handshake has not been sent bit 4 idleif: idle detect interrupt bit ( 1 ) 1 = idle condition is detected (constant idle state of 3 ms or more) 0 = no idle condition is detected bit 3 trnif: transaction complete interrupt bit ( 2 ) 1 = processing of pending transaction is complete; read the ustat register for endpoint information 0 = processing of pending transaction is not complete or no transaction is pending bit 2 actvif: bus activity detect interrupt bit ( 3 ) 1 = activity on the d+/d- lines was detected 0 = no activity detected on the d+/d- lines bit 1 uerrif: usb error condition interrupt bit ( 4 ) 1 = an unmasked error condition has occurred 0 = no unmasked error condition has occurred. bit 0 urstif: usb reset interrupt bit 1 = valid usb reset occurred; 00h is loaded into the uaddr register 0 = no usb reset has occurred note 1: once an idle state is detected, the user may want to place the usb module in suspend mode. 2: clearing this bit will cause the ustat fifo to advance (valid only for in, out and setup tokens). 3: this bit is typically unmasked only following the detection of a uidle interrupt event. 4: only error conditions enabled through the ueie register will set this bit. this bit is a status bit only and cannot be set or cleared by the user.
pic18f97j94 family ds30575a-page 542 ? 2012 microchip technology inc. 27.5.1.1 bus activity detect interrupt bit (actvif) the actvif bit cannot be cleared immediately after the usb module wakes up from suspend mode or while the usb module is suspended. a few clock cycles are required to synchronize the internal hard- ware state machine before the actvif bit can be cleared by firmware. clearing the actvif bit before the internal hardware is synchronized may not have an effect on the value of actvif. additionally, if the usb module uses the clock from the 96 mhz pll source, then after clearing the suspnd bit, the usb module may not be immediately operational while waiting for the 96 mhz pll to lock. the application code should clear the actvif flag as provided in example 27-1 . example 27-1: clearing actvif bit (uir<2>) note: only one actvif interrupt is generated when resuming from the usb bus idle con- dition. if user firmware clears the actvif bit, the bit will not immediately become set again, even when there is continuous bus traffic. bus traffic must cease long enough to generate another idleif condition before another actvif interrupt can be generated. assembly: bcf ucon, suspnd loop: btfss uir, actvif bra done bcf uir, actvif bra loop done: c: uconbits.suspnd = 0; while (uirbits.actvif) { uirbits.actvif = 0; }
? 2012 microchip technology inc. ds30575a-page 543 pic18f97j94 family 27.5.2 usb interrupt enable register (uie) the usb interrupt enable (uie) register ( register 27-8 ) contains the enable bits for the usb status interrupt sources. setting any of these bits will enable the respective interrupt source in the uir register. the values in this register only affect the propagation of an interrupt condition to the microcontroller?s inter- rupt logic. the flag bits are still set by their interrupt conditions, allowing them to be polled and serviced without actually generating an interrupt. register 27-8: uie: usb interrupt enable register u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? sofie stallie idleie trnie actvie uerrie urstie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 sofie: start-of-frame token interrupt enable bit 1 = start-of-frame token interrupt is enabled 0 = start-of-frame token interrupt is disabled bit 5 stallie: stall handshake interrupt enable bit 1 = stall interrupt is enabled 0 = stall interrupt is disabled bit 4 idleie: idle detect interrupt enable bit 1 = idle detect interrupt is enabled 0 = idle detect interrupt is disabled bit 3 trnie: transaction complete interrupt enable bit 1 = transaction interrupt is enabled 0 = transaction interrupt is disabled bit 2 actvie: bus activity detect interrupt enable bit 1 = bus activity detect interrupt is enabled 0 = bus activity detect interrupt is disabled bit 1 uerrie: usb error interrupt enable bit 1 = usb error interrupt is enabled 0 = usb error interrupt is disabled bit 0 urstie: usb reset interrupt enable bit 1 = usb reset interrupt is enabled 0 = usb reset interrupt is disabled
pic18f97j94 family ds30575a-page 544 ? 2012 microchip technology inc. 27.5.3 usb error interrupt status register (ueir) the usb error interrupt status register ( register 27-9 ) contains the flag bits for each of the error sources within the usb peripheral. each of these sources is controlled by a corresponding interrupt enable bit in the ueie register. all of the usb error flags are ored together to generate the usb error interrupt flag (uerrif) at the top level of the interrupt logic. each error bit is set as soon as the error condition is detected. thus, the interrupt will typically not correspond with the end of a token being processed. once an interrupt bit has been set by the sie, it must be cleared in software by writing a ? 0 ?. register 27-9: ueir: usb error interr upt status register (access f63h) r/c-0 u-0 u-0 r/c-0 r/c-0 r/c-0 r/c-0 r/c-0 btsef ? ? btoef dfn8ef crc16ef crc5ef pidef bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 btsef: bit stuff error flag bit 1 = a bit stuff error has been detected 0 = no bit stuff error has been detected bit 6-5 unimplemented: read as ? 0 ? bit 4 btoef: bus turnaround time-out error flag bit 1 = bus turnaround time-out has occurred (more than 16 bit times of idle from previous eop elapsed) 0 = no bus turnaround time-out has occurred bit 3 dfn8ef: data field size error flag bit 1 = the data field was not an integral number of bytes 0 = the data field was an integral number of bytes bit 2 crc16ef: crc16 failure flag bit 1 = the crc16 failed 0 = the crc16 passed bit 1 crc5ef: crc5 host error flag bit 1 = the token packet was rejected due to a crc5 error 0 = the token packet was accepted bit 0 pidef: pid check failure flag bit 1 = pid check failed 0 = pid check passed
? 2012 microchip technology inc. ds30575a-page 545 pic18f97j94 family 27.5.4 usb error interrupt enable register (ueie) the usb error interrupt enable register ( register 27-10 ) contains the enable bits for each of the usb error interrupt sources. setting any of these bits will enable the respective error interrupt source in the ueir register to propagate into the uerr bit at the top level of the interrupt logic. as with the uie register, the enable bits only affect the propagation of an interrupt condition to the micro- controller?s interrupt logic. the flag bits are still set by their interrupt conditions, allowing them to be polled and serviced without actually generating an interrupt. register 27-10: ueie: usb error interrupt enable register (banked f37h) r/w-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 btsee ? ? btoee dfn8ee crc16ee crc5ee pidee bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 btsee: bit stuff error interrupt enable bit 1 = bit stuff error interrupt is enabled 0 = bit stuff error interrupt is disabled bit 6-5 unimplemented: read as ? 0 ? bit 4 btoee: bus turnaround time-out error interrupt enable bit 1 = bus turnaround time-out error interrupt is enabled 0 = bus turnaround time-out error interrupt is disabled bit 3 dfn8ee: data field size error interrupt enable bit 1 = data field size error interrupt is enabled 0 = data field size error interrupt is disabled bit 2 crc16ee: crc16 failure interrupt enable bit 1 = crc16 failure interrupt is enabled 0 = crc16 failure interrupt is disabled bit 1 crc5ee: crc5 host error interrupt enable bit 1 = crc5 host error interrupt is enabled 0 = crc5 host error interrupt is disabled bit 0 pidee: pid check failure interrupt enable bit 1 = pid check failure interrupt is enabled 0 = pid check failure interrupt is disabled
pic18f97j94 family ds30575a-page 546 ? 2012 microchip technology inc. 27.6 usb power modes many usb applications will likely have several different sets of power requirements and configuration. the most common power modes encountered are bus power only, self-power only and dual power with self-power dominance. the most common cases are presented here. also provided is a means of estimating the current consumption of the usb transceiver. 27.6.1 bus power only in bus power only mode, all power for the application is drawn from the usb ( figure 27-9 ). this is effectively the simplest power method for the device. in order to meet the inrush current requirements of the ? usb 2.0 specification ?, the total effective capacitance appearing across v bus and ground must be no more than 10 f. if not, some kind of inrush timing is required. for more details, see section 7.2.4 of the ? usb 2.0 specification ?. according to the ? usb 2.0 specification ?, all usb devices must also support a low-power suspend mode. in the usb suspend mode, devices must consume no more than 2.5 ma from the 5v v bus line of the usb cable. the host signals the usb device to enter the suspend mode by stopping all usb traffic to that device for more than 3 ms. this condition will cause the idleif bit in the uir register to become set. during the usb suspend mode, the d+ or d- pull-up resistor must remain active, which will consume some of the allowed suspend current: 2.5 ma budget. figure 27-9: bus power only 27.6.2 self-power only in self-power only mode, the usb application provides its own power, with very little power being pulled from the usb. see figure 27-10 for an example. note that an attach indication is added to indicate when the usb has been connected and the host is actively powering v bus . in order to meet compliance specifications, the usb module (and the d+ or d- pull-up resistor) should not be enabled until the host actively drives v bus high. one of the 5.5v tolerant i/o pins may be used for this purpose. the application should never source any current onto the 5v v bus pin of the usb cable. figure 27-10: self-power only 27.6.3 dual power with self-power dominance some applications may require a dual power option. this allows the application to use internal power primarily, but switch to power from the usb when no internal power is available. see figure 27-11 for a simple dual power with self-power dominance mode example, which automatically switches between self- power only and usb bus power only modes. dual power devices must also meet all of the special requirements for inrush current and suspend mode current, and must not enable the usb module until v bus is driven high. see section 27.6.1 ?bus power only? and section 27.6.2 ?self-power only? for descriptions of those requirements. additionally, dual power devices must never source current onto the 5v v bus pin of the usb cable. figure 27-11: dual power with self-power dominance v dd v usb 3 v 3 v ss v bus ~5v 3.3v low i q regulator note: users should keep in mind the limits for devices drawing power from the usb. according to usb specification 2.0, this cannot exceed 100 ma per low-power device or 500 ma per high-power device. v dd v usb 3 v 3 v ss v self ~3.3v attach sense 100 k ? 100 k ? v bus ~5v 5.5v tolerant i/o pin v dd v usb 3 v 3 i/o pin v ss attach sense v bus v self 100 k ? ~3.3v ~5v 100 k ? 3.3v low i q regulator
? 2012 microchip technology inc. ds30575a-page 547 pic18f97j94 family 27.6.4 usb transceiver current consumption the usb transceiver consumes a variable amount of current depending on the characteristic impedance of the usb cable, the length of the cable, the v usb 3 v 3 supply voltage and the actual data patterns moving across the usb cable. longer cables have larger capacitances and consume more total energy when switching output states. data patterns that consist of ?in? traffic consume far more current than ?out? traffic. in traffic requires the pic ? mcu to drive the usb cable, whereas out traffic requires that the host drive the usb cable. the data that is sent across the usb cable is nrzi encoded. in the nrzi encoding scheme, ? 0 ? bits cause a toggling of the output state of the transceiver (either from a ?j? state to a ?k? state or vise versa). with the exception of the effects of bit stuffing, nrzi encoded ? 1 ? bits do not cause the output state of the transceiver to change. therefore, in traffic consisting of data bits of value, ? 0 ?, cause the most current consumption, as the transceiver must charge/discharge the usb cable in order to change states. more details about nrzi encoding and bit stuffing can be found in the ? usb 2.0 specification ?, section 7.1, although knowledge of such details is not required to make usb applications using the pic18f97j94 family of microcontrollers. among other things, the sie handles bit stuffing/unstuffing, nrzi encoding/decoding and crc generation/checking in hardware. the total transceiver current consumption will be application-specific. however, to help estimate how much current actually may be required in full-speed applications, equation 27-1 can be used. see equation 27-2 to know how this equation can be used for a theoretical application. equation 27-1: estimating usb t ransceiver current consumption i xcvr = + i pullup (4 0 ma ? v usb 3 v 3 ? p zero ? p in ? l cable ) (3.3v ? 5 m) legend: v usb 3 v 3 ? voltage applied to the v usb 3 v 3 pin in volts (should be 3.0v to 3.6v). p zero ? percentage (in decimal) of the in traffic bits sent by the pic ? mcu that are a value of ? 0 ?. p in ? percentage (in decimal) of total bus bandwidth that is used for in traffic. l cable ? length (in meters) of the usb cable. the ? usb 2.0 specification ? requires that full-speed applications use cables no longer than 5m. i pullup ? current which the nominal, 1.5 k ? pull-up resistor (when enabled) must supply to the usb cable. on the host or hub end of the usb cable, 15 k ? nominal resistors (14.25 k ? to 24.8 k ? ) are present which pull both the d+ and d- lines to ground. during bus idle conditions (such as between packets or during usb suspend mode), this results in up to 218 ? a of quiescent current drawn at 3.3v. i pullup is also dependant on bus traffic conditions and can be as high as 2.2 ma when the usb bandwidth is fully utilized (either in or out traffic) for data that drives the lines to the ?k? state most of the time.
pic18f97j94 family ds30575a-page 548 ? 2012 microchip technology inc. equation 27-2: calculating usb transceiver current ? for this example, the following assumptions are made about the application: ? 3.3v will be applied to v usb 3 v 3 and v dd , with the core voltage regulator enabled. ? this is a full-speed application that uses one interrupt in endpoint that can send one packet of 64 bytes every 1 ms, with no restrictions on the values of the bytes being sent. the application may or may not have additional traffic on out endpoints. ? a regular usb ?b? or ?mini-b? connector will be used on the application circuit board. in this case, p zero = 100% = 1, because there should be no restriction on the value of the data moving through the in endpoint. all 64 kbps of data could potentially be bytes of value, 00h. since ? 0 ? bits cause toggling of the output state of the transceiver, they cause the usb transceiver to consume extra current charging/discharging the cable. in this case, 100% of the data bits sent can be of value ? 0 ?. this should be considered the ?max? value, as normal data will consist of a fair mix of ones and zeros. this application uses 64 kbps for in traffic out of the total bus bandwidth of 1.5 mbps (12 mbps), therefore: since a regular ?b? or ?mini-b? connector is used in this application, the end user may plug in any type of cable up to the maximum allowed 5m length. therefore, we use the worst-case length: l cable = 5 meters assume i pullup = 2.2 ma. the actual value of i pullup will likely be closer to 218 ? a, but allowance for the worst-case. usb bandwidth is shared between all the devices which are plugged into the root port (via hubs). if the application is plugged into a usb 1.1 hub that has other devices plugged into it, your device may see host to device traffic on the bus, even if it is not addressed to your device. since any traffic, regardless of source, can increase the i pullup current above the base 218 ? a, it is safest to allow for the worst-case of 2.2 ma. therefore: ? the calculated value should be considered an approximation and additional guardband or application- specific product testing is recommended. the transceiver current is ?in addition to? the rest of the current consumed by the pic18f97j94 family device that is needed to run the core, drive the other i/o lines, power the various modules, etc. pin = 64 kbps 1.5 mbps = 4.3% = 0.043 i xcvr = + 2.2 ma = 3.9 ma (40 ma ? 3.3v ? 1 ? 0.043 ? 5m) (3.3v ? 5m)
? 2012 microchip technology inc. ds30575a-page 549 pic18f97j94 family 27.7 oscillator the usb module has specific clock requirements. for full-speed operation, the clock source must be 48 mhz. even so, the microcontroller core and other peripherals are not required to run at that clock speed. 27.8 usb firmware and drivers microchip provides a number of application-specific resources, such as usb firmware and driver support. refer to www.microchip.com for the latest firmware and driver support. table 27-4: registers associat ed with usb module operation ( 1 ) name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie iocie tmr0if int0if iocif ipr2 oscfip ssp2ip bcl2ip usbip bcl1ip hlvdip tmr3ip tmr3gip pir2 oscfif ssp2if bcl2if usbif bcl1if hlvdif tmr3if tmr3gif pie2 oscfie ssp2ie bcl2ie usbie bcl1ie hlvdie tmr3ie tmr3gie ucon ? ppbrst se0 pktdis usben resume suspnd ? ucfg uteye uoemon ? upuen utrdis fsen ppb1 ppb0 ustat ? endp3 endp2 endp1 endp0 dir ppbi ? uaddr ? addr6 addr5 addr4 addr3 addr2 addr1 addr0 ufrml frm7 frm6 frm5 frm4 frm3 frm2 frm1 frm0 ufrmh ? ? ? ? ?frm10frm9frm8 uir ? sofif stallif idleif trnif actvif uerrif urstif uie ? sofie stallie idleie trnie actvie uerrie urstie ueir btsef ? ? btoef dfn8ef crc16ef crc5ef pidef ueie btsee ? ? btoee dfn8ee crc16ee crc5ee pidee uep0 ? ? ? ephshk epcondis epouten epinen epstall uep1 ? ? ? ephshk epcondis epouten epinen epstall uep2 ? ? ? ephshk epcondis epouten epinen epstall uep3 ? ? ? ephshk epcondis epouten epinen epstall uep4 ? ? ? ephshk epcondis epouten epinen epstall uep5 ? ? ? ephshk epcondis epouten epinen epstall uep6 ? ? ? ephshk epcondis epouten epinen epstall uep7 ? ? ? ephshk epcondis epouten epinen epstall uep8 ? ? ? ephshk epcondis epouten epinen epstall uep9 ? ? ? ephshk epcondis epouten epinen epstall uep10 ? ? ? ephshk epcondis epouten epinen epstall uep11 ? ? ? ephshk epcondis epouten epinen epstall uep12 ? ? ? ephshk epcondis epouten epinen epstall uep13 ? ? ? ephshk epcondis epouten epinen epstall uep14 ? ? ? ephshk epcondis epouten epinen epstall uep15 ? ? ? ephshk epcondis epouten epinen epstall legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the usb module. note 1: this table includes only those hardware mapped sfrs locate d in bank 15 of the data memory space. the buffer descriptor registers, which are mapped into bank 4 and are not true sfrs, are listed separately in table 27-3 .
pic18f97j94 family ds30575a-page 550 ? 2012 microchip technology inc. 27.9 overview of usb this section presents some of the basic usb concepts and useful information necessary to design a usb device. although much information is provided in this section, there is a plethora of information provided within the usb specifications and class specifications. thus, the reader is encouraged to refer to the usb specifications for more information ( www.usb.org ). if you are very familiar with the details of usb, then this section serves as a basic, high-level refresher of usb. 27.9.1 layered framework usb device functionality is structured into a layered framework, graphically illustrated in figure 27-12 . each level is associated with a functional level within the device. the highest layer, other than the device, is the configuration. a device may have multiple configu- rations. for example, a particular device may have multiple power requirements based on self-power only or bus power only modes. for each configuration, there may be multiple interfaces. each interface could support a particular mode of that configuration. below the interface is the endpoint(s). data is directly moved at this level. there can be as many as 16 bidirectional endpoints. endpoint 0 is always a control endpoint, and by default, when the device is on the bus, endpoint 0 must be available to configure the device. 27.9.2 frames information communicated on the bus is grouped into 1 ms time slots, referred to as frames. each frame can contain many transactions to various devices and endpoints. see figure 27-8 for an example of a transaction within a frame. 27.9.3 transfers there are four transfer types defined in the usb specification. ? isochronous: this type provides a transfer method for large amounts of data (up to 1023 bytes) with timely delivery ensured; however, the data integrity is not ensured. this is good for streaming applications where small data loss is not critical, such as audio. ? bulk: this type of transfer method allows for large amounts of data to be transferred with ensured data integrity; however, the delivery timeliness is not ensured. ? interrupt: this type of transfer provides for ensured timely delivery for small blocks of data, plus data integrity is ensured. ? control: this type provides for device setup control. while full-speed devices support all transfer types, low- speed devices are limited to interrupt and control transfers only. 27.9.4 power power is available from the usb. the usb specifica- tion defines the bus power requirements. devices may either be self-powered or bus-powered. self-powered devices draw power from an external source, while bus-powered devices use power supplied from the bus. figure 27-12: usb layers device endpoint endpoint endpoint endpoint endpoint to other configurations (if any) to other interfaces (if any) configuration interface interface
? 2012 microchip technology inc. ds30575a-page 551 pic18f97j94 family the usb specification limits the power taken from the bus. each device is ensured 100 ma at approximately 5v (one unit load). additional power may be requested, up to a maximum of 500 ma. note that power above one unit load is a request and the host or hub is not obligated to provide the extra cur- rent. thus, a device capable of consuming more than one unit load must be able to maintain a low-power configuration of a one unit load or less, if necessary. the usb specification also defines a suspend mode. in this situation, current must be limited to 500 ? a, averaged over one second. a device must enter a suspend state after 3 ms of inactivity (i.e., no sof tokens for 3 ms). a device entering suspend mode must drop current consumption within 10 ms after suspend. likewise, when signaling a wake-up, the device must signal a wake-up within 10 ms of drawing current above the suspend limit. 27.9.5 enumeration when the device is initially attached to the bus, the host enters an enumeration process in an attempt to identify the device. essentially, the host interrogates the device, gathering information, such as power consumption, data rates and sizes, protocol and other descriptive information; descriptors contain this information. a typical enumeration process would be as follows: 1. usb reset ? reset the device. thus, the device is not configured and does not have an address (address 0). 2. get device descriptor ? the host requests a small portion of the device descriptor. 3. usb reset ? reset the device again. 4. set address ? the host assigns an address to the device. 5. get device descriptor ? the host retrieves the device descriptor, gathering info, such as manufacturer, type of device, maximum control packet size. 6. get configuration descriptors. 7. get any other descriptors. 8. set a configuration. the exact enumeration process depends on the host. 27.9.6 descriptors there are eight different standard descriptor types, of which, five are most important for this device. 27.9.6.1 device descriptor the device descriptor provides general information, such as manufacturer, product number, serial number, the class of the device and the number of configurations. there is only one device descriptor. 27.9.6.2 configuration descriptor the configuration descriptor provides information on the power requirements of the device and how many different interfaces are supported when in this configu- ration. there may be more than one configuration for a device (i.e., low-power and high-power configurations). 27.9.6.3 interface descriptor the interface descriptor details the number of end- points used in this interface, as well as the class of the interface. there may be more than one interface for a configuration. 27.9.6.4 endpoint descriptor the endpoint descriptor identifies the transfer type ( section 27.9.3 ?transfers? ) and direction, and some other specifics for the endpoint. there may be many endpoints in a device and endpoints may be shared in different configurations. 27.9.6.5 string descriptor many of the previous descriptors reference one or more string descriptors. string descriptors provide human readable information about the layer ( section 27.9.1 ?layered framework? ) they describe. often these strings show up in the host to help the user identify the device. string descriptors are generally optional to save memory and are encoded in a unicode format. 27.9.7 bus speed each usb device must indicate its bus presence and speed to the host. this is accomplished through a 1.5 k ? resistor, which is connected to the bus at the time of the attachment event. depending on the speed of the device, the resistor either pulls up the d+ or d- line to 3.3v. for a low- speed device, the pull-up resistor is connected to the d- line. for a full-speed device, the pull-up resistor is connected to the d+ line. 27.9.8 class specifications and drivers usb specifications include class specifications, which operating system vendors optionally support. examples of classes include: audio, mass storage, communications and human interface (hid). in most cases, a driver is required at the host side to ?talk? to the usb device. in custom applications, a driver may need to be developed. fortunately, drivers are available for most common host systems for the most common classes of devices. thus, these drivers can be reused.
pic18f97j94 family ds30575a-page 552 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 553 pic18f97j94 family 28.0 special features of the cpu the pic18f97j94 family of devices includes several features intended to maximize reliability and minimize cost through elimination of external components. these include: ? oscillator selection ? resets: - power-on reset (por) - power-up timer (pwrt) - oscillator start-up timer (ost) - brown-out reset (bor) ? interrupts ? watchdog timer (wdt) and on-chip regulator ? fail-safe clock monitor ? two-speed start-up ? code protection ? id locations ? in-circuit serial programming? the oscillator can be configured for the application depending on frequency, power, accuracy and cost. all of the options are discussed in detail in section 3.0 ?oscillator configurations? . a complete discussion of device resets and interrupts is available in previous sections of this data sheet. in addition to their power-up and oscillator start-up timers provided for resets, the pic18f97j94 family of devices has a watchdog timer, which is either perma- nently enabled via the configuration bits or software controlled (if configured as disabled). the inclusion of an internal rc oscillator (lf-intosc) also provides the additional benefits of a fail-safe clock monitor (fscm) and two-speed start-up. fscm provides for background monitoring of the peripheral clock and automatic switchover in the event of its failure. two-speed start-up enables code to be exe- cuted almost immediately on start-up, while the primary clock source completes its start-up delays. all of these features are enabled and configured by setting the appropriate configuration register bits. 28.1 configuration bits devices of the pic18f97j94 family do not use persis- tent memory registers to st ore configuration information. the configuration registers, config1l through config8h, are implemented as volatile memory. immediately after power-up, or after a device reset, the microcontroller hardware automatically loads the config1l through config8h registers with configu- ration data stored in nonvolatile flash program memory. the last eight words of flash program memory, known as the flash configuration words (fcw), are used to store the configuration data. table 28-2 provides the flash program memory, which will be loaded into the corresponding configuration register. when creating applications for these devices, users should always specifically allocate the location of the fcw for configuration data. this is to make certain that program code is not stored in this address when the code is compiled. the four most significant bits (msb) of the fcw, corre- sponding to config1h, config2h, config3h, config4h, config5h, config6h, config7h and config8h, should always be programmed to ? 1111 ?. this makes these fcws appear to be nop instructions in the remote event that their locations are ever executed by accident. the four msbs of the config1h, config2h, config3h, config4h config5h, config6h, config7h and config8h, registers are not imple- mented, so writing ? 1 ?s to their corresponding fcw has no effect on device operation. to prevent inadvertent configuration changes during code execution, the configuration registers, config1l through config8h, are loaded only once per power-up or reset cycle. user?s firmware can still change the configuration by using self-reprogramming to modify the contents of the fcw. modifying the fcw will not change the active contents being used in the config1l through config8h registers until after the device is reset.
pic18f97j94 family ds30575a-page 554 ? 2012 microchip technology inc. table 28-1: mapping of the flash conf iguration words to the configuration registers configuration register (volatile) configuration register address flash configuration byte address config1l 300000h xxxf0h config1h 300001h xxxf1h config2l 300002h xxxf2h config2h 300003h xxxf3h config3l 300004h xxxf4h config3h 300005h xxxf5h config4l 300006h xxxf6h config4h 300007h xxxf7h config5l 300008h xxxf8h config5h 300009h xxxf9h config6l 30000ah xxxfah config6h 30000bh xxxfbh config7l 30000ch xxxfch config7h 30000dh xxxfdh config8l 30000eh xxxfeh config8h 30000fh xxxffh table 28-2: configuration bits and device ids file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 default/ unprogrammed value 300000h config1l debug xinst stvren ? ? ? ? ? 111- ---- 300001h config1h ? ( 2 ) ? ( 2 ) ? ( 2 ) ? ( 2 ) ? ( 1 ) cp0 borv boren ---- -111 300002h config2l ieso ?clkoen ? soscsel fosc2 fosc1 fosc0 1-1- 1111 300003h config2h ? ( 2 ) ? ( 2 ) ? ( 2 ) ? ( 2 ) plldiv3 plldiv2 plldiv1 plldiv0 ---- 1111 300004h config3l ? ?fscm1fscm0 ? ?poscmd1poscmd0 --11 --11 300005h config3h ? ( 2 ) ? ( 2 ) ? ( 2 ) ? ( 2 ) ? ? ? ? 1111 ---- 300006h config4l wpfp7 wpfp6 wpfp5 wpfp4 wpfp3 wpfp2 wpfp1 wpfp0 1111 1111 300007h config4h ? ( 2 ) ? ( 2 ) ? ( 2 ) ? ( 2 ) ? wpcfg wpend wpdis ---- -111 300008h config5l wait bw abw1 abw0 eashft ? cinasel t5gsel 1111 1-11 300009h config5h ? ( 2 ) ? ( 2 ) ? ( 2 ) ? ( 2 ) msspmsk1 msspmsk2 ls48mhz iol1way 1111 1111 30000ah config6l wdps3 wdps2 wdps1 wdps0 wdtclk1 wdtclk0 wdtwin1 wdtwin0 1111 1111 30000bh config6h ? ( 2 ) ? ( 2 ) ? ( 2 ) ? ( 2 ) wpsa windis wdten1 wdten0 1111 1111 30000ch config7l ? ? ? dsbiten dsboren vbtbor ? reten ---1 11-1 30000dh config7h ? ( 2 ) ? ( 2 ) ? ( 2 ) ? ( 2 ) ? ? ? ? 1111 ---- 30000eh config8l dswdtps4 dswdtps3 dswdtps2 dswdtps1 dswdtps0 ? ? ? 1111 1--- 30000fh config8h ? ( 2 ) ? ( 2 ) ? ( 2 ) ? ( 2 ) ? ? dswdtosc dswdten 1111 --11 3ffffeh devid1 dev2 dev1 dev0 rev4 rev3 rev2 rev1 rev0 see register 28-16 3fffffh devid2 dev10 dev9 dev8 dev7 dev6 dev5 dev4 dev3 see register 28-15 legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition. shaded cells are unimplemented, read as ? 0 ?. note 1: this bit should always be maintained as ? 0 ?. 2: the value of these bits in program memory should always be programmed to ? 1 ?. this ensures that the location is executed as a nop if it is accidentally executed.
? 2012 microchip technology inc. ds30575a-page 555 pic18f97j94 family register 28-1: config1l: configuration register 1 low (byte address 300000h) r/wo-1 r/wo-1 r/wo-1 u-1 u-1 u-1 u-1 u-1 debug xinst stvren ? ? ? ? ? bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 debug : background debugger enable bit 1 = background debugger is disabled, and rb6 and rb7 are configured as general purpose i/o pins 0 = background debugger is enabled, and rb6 and rb7 are dedicated to in-circuit debug bit 6 xinst: extended instruction set enable bit 1 = instruction set extension and indexed addressing mode are enabled 0 = instruction set extension and indexed addressing mode are disabled (legacy mode) bit 5 stvren: stack overflow reset enable bit 1 = reset on stack overflow/underflow is enabled 0 = reset on stack overflow/underflow is disabled bit 4-0 unimplemented: read as ? 1 ? register 28-2: config1h: configuration register 1 high (byte address 300001h) u-1 u-1 u-1 u-1 u-0 r/wo-1 r/wo-1 r/wo-1 ? ? ? ? ? cp0 borv boren bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: read as ? ? ? bit 3 unimplemented: maintain as ? 0 ? bit 2 cp0: code protection bit 0 1 = program memory is not code-protected 0 = program memory is code-protected (and write-protected in test modes) bit 1 borv: bor trip point select bit 1 = bor trip point is 1.8v 0 = bor trip point is 2.0v bit 0 boren: brown-out reset enable bit 1 = brown-out reset is disabled 0 = brown-out reset is enabled outside of deep sleep (borv is always disabled in deep sleep)
pic18f97j94 family ds30575a-page 556 ? 2012 microchip technology inc. register 28-3: config2l: configuration register 2 low (byte address 300002h) ( 1 , 2 , 3 , 4 ) r/wo-1 u-1 r/wo-0 u-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 ieso ?clkoen ? soscsel fosc2 fosc1 fosc0 bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ieso: internal external switch over bit 1 = internal/external switchover mode is enabled (two-speed start-up is enabled) 0 = internal/external switchover mode is disabled (two-speed start-up is disabled) bit 6 unimplemented: read as ? 1 ? bit 5 clkoen: clko enable configuration bit 1 = clko output signal is active on the osc2 pin; primary oscillator must be disabled or configured for the external clock mode (ec) for the clko to be active (poscmd<1:0> = 11 or 00 ) 0 = clko output disabled bit 4 unimplemented: read as ? 0 ? bit 3 soscsel: sosc selection configuration bit 1 = low-power sosc circuit is selected (typical i dd of 1 a) 0 = digital (sclki) mode bit 2-0 fosc<2:0>: oscillator selection bits 000 = fast rc oscillator (frc) 001 = fast rc oscillator with divide-by-n with pll module (frcdiv+pll) 010 = primary oscillator (ms, hs, ec) 011 = primary oscillator with pll module (ms+pll, hs+pll, ec+pll) 100 = secondary oscillator (sosc) 101 = low-power rc oscillator (lprc) 110 = fast rc oscillator (frc) divided by 16 (500 khz) 111 = fast rc oscillator with divide-by-n (frcdiv) note 1: the config2l bits can only be programmed indirectly by programming the flash configuration word. 2: the config2l is reset to ? 1 ? only on v dd reset; it is reloaded with the programmed value at any device reset. 3: although config2l is reset to ? 1 ? only on v dd reset, these values are not used until after the actual con- figuration values are read out and stored in the register bits. therefore, for these bits, the reset value has no effect on the operation of the system. 4: unlike other configuration registers, the clkoen holding register is reset to a ? 0 ? on any v dd reset. this prevents the clko pin from driving until the actual configuration values are read out and stored in the register.
? 2012 microchip technology inc. ds30575a-page 557 pic18f97j94 family register 28-4: config2h: configuration register 2 high (byte address 300003h) ( 1 , 2 ) u-1 u-1 u-1 u-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 ? ? ? ? plldiv3 ( 3 ) plldiv2 ( 3 ) plldiv1 ( 3 ) plldiv0 ( 3 ) bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: program the corresponding flash configuration bit to ? 1 ? bit 3-0 plldiv<3:0>: frequency multiplier select bits ( 3 ) divider must be selected so as to not exceed 64 mhz output. 1111 = no pll used; pllen bit is not available to user 1110 = 8x pll is selected 1101 = 6x pll is selected 1100 = 4x pll is selected 1011 = reserved; do not use 1010 = reserved; do not use 1001 = reserved; do not use 1000 = reserved; do not use 0111 = 96 mhz pll is selected; oscillator divided by 12 (48 mhz input) 0110 = 96 mhz pll is selected; oscillator divided by 10 (40 mhz input) 0101 = 96 mhz pll is selected; oscillator divided by 6 (24 mhz input) 0100 = 96 mhz pll is selected; oscillator divided by 5 (20 mhz input) 0011 = 96 mhz pll is selected; oscillator divided by 4 (16 mhz input) 0010 = 96 mhz pll is selected; oscillator divided by 3 (12 mhz input) 0001 = 96 mhz pll is selected; oscillator divided by 2 (8 mhz input) 0000 = 96 mhz pll is selected; no divide ? oscillator is used directly (4 mhz input) note 1: the config2h bits can only be programmed indirectly by programming the flash configuration word. 2: the config2h is reset to ? 1 ? only on v dd reset; it is reloaded with the programmed value at any device reset. 3: if usb functionality is used, then this field must be set to ? 0xxx ? (i.e., 96 mhz pll is selected).
pic18f97j94 family ds30575a-page 558 ? 2012 microchip technology inc. register 28-5: config3l: configuration register 3 low (byte address 300004h) ( 1 , 2 ) u-1 u-1 r/wo-1 r/wo-1 u-1 u-0 r/wo-1 r/wo-1 ? ?fscm1 fscm0 ? ? poscmd1 poscmd0 bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 1 ? bit 5-4 fscm<1:0>: clock switching and monitor selection configuration bits 1x = clock switching is disabled, fail-safe clock monitor is disabled 01 = clock switching is enabled, fail-safe clock monitor is disabled 00 = clock switching is enabled, fail-safe clock monitor is enabled bit 3-2 unimplemented: read as ? 0 ? bit 1-0 poscmd<1:0>: primary oscillator configuration bits 11 = primary oscillator is disabled 10 = hs oscillator mode is selected (10 mhz-40 mhz) 01 = ms oscillator mode is selected (3.5 mhz-10 mhz) 00 = external clock mode is selected note 1: the config3l bits can only be programmed indirectly by programming the flash configuration word. 2: the config3l is reset to ? 1 ? only on v dd reset; it is reloaded with the programmed value at any device reset.
? 2012 microchip technology inc. ds30575a-page 559 pic18f97j94 family register 28-6: config4l: configuration register 4 low (byte address 300006h) r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 wpfp7 wpfp6 wpfp5 wpfp4 wpfp3 wpfp2 wpfp1 wpfp0 bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 wpfp<7:0>: write-protect program flash pages bits (valid when wpdis = 0 ) when wpend = 0 : write/erase protect flash memory pages, starting at page 0 and ending with page wpfp<7:0>. when wpend = 1 : write/erase protect flash memory pages, starting at page wpfp<7:0> and ending with the last page in user flash. register 28-7: config4h: configuration register 4 high (byte address 300007h) u-1 u-1 u-1 u-1 u-1 r/wo-1 r/wo-1 r/wo-1 ? ? ? ? ? wpcfg wpend wpdis bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-3 unimplemented: program the corresponding flash configuration bit to ? 1 ? bit 2 wpcfg: write/erase protect last page in user flash bit 1 = write/erase protection of last page is disabled, regardless of the wpfp<7:0> setting 0 = write/erase protection of last page is enabled, regardless of the wpfp<7:0> setting bit 1 wpend: write protection end page bit this bit is valid when wpdis = 0 . when wpend = 0 : write/erase protect flash memory pages, starting at page 0 and ending with page wpfp<7:0>. when wpend = 1 : write/erase protect flash memory pages, starting at page wpfp<7:0> and ending with the last page in user flash. bit 0 wpdis: write-protect disable bit 1 = wpfp<7:0>, wpend and wpcfg bits are ignored 0 = wpfp<7:0>, wpend and wpcfg bits are enabled; write-protect is active
pic18f97j94 family ds30575a-page 560 ? 2012 microchip technology inc. register 28-8: config5l: configuration register 5 low (byte address 300008h) r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 u-1 r/wo-1 r/wo-1 wait ( 1 ) bw abw1 abw0 eashft ? cinasel t5gsel bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wait: external bus wait enable bit ( 1 ) 1 = wait selections from wait<1:0> (memcon<5:4>) are unavailable and the device will not wait 0 = wait is programmed by wait<1:0> (memcon<5:4>) bit 6 bw: data bus width select bit 1 = 16-bit external bus mode 0 = 8-bit external bus mode bit 5-4 abw<1:0>: external memory bus configuration bits 00 = extended microcontroller mode ? 20-bit address mode 01 = extended microcontroller mode ? 16-bit address mode 10 = extended microcontroller mode ? 12-bit address mode 11 = microcontroller mode ? external bus is disabled bit 3 eashft: external address bus shift enable bit 1 = address shifting is enabled ? external address bus is shifted to start at 000000h 0 = address shifting is disabled ? external address bus reflects the pc value bit 2 unimplemented: read as ? 0 ? bit 1 cinasel: cxina gate select bit 1 = c1ina and c3ina are on their default pin locations 0 = c1ina and c3ina are all remapped to pin, ra5 bit 0 t5gsel: tmr5 gate select bit 1 = tmr5 gate is driven by the t5g input 0 = tmr5 gate is driven by the t3g input note 1: this bit was previously referred to as ?wait?, but a set condition actually indicates the case where the emb does not wait and the name was therefore changed to reflect this. no change in functionality or polarity occurred, only a change in the name of the register bit.
? 2012 microchip technology inc. ds30575a-page 561 pic18f97j94 family register 28-9: config5h: configuration register 5 high (byte address 300009h) u-1 u-1 u-1 u-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 ? ? ? ? msspmsk1 msspmsk2 ls48mhz iol1way bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: program the corresponding flash configuration bit to ? 1 ? bit 3 msspmsk1: mssp1 7-bit address masking mode enable bit 1 = 7-bit address masking mode enable 0 = 5-bit address masking mode enable bit 2 msspmsk2: mssp2 7-bit address masking mode enable bit 1 = 7-bit address masking mode enable 0 = 5-bit address masking mode enable bit 1 ls48mhz: low-speed usb clock selection bit 1 = 48 mhz system clock is expected; divide-by-8 generates low-speed usb clock 0 = 24 mhz system clock is expected; divide-by-4 generates low-speed usb clock bit 0 iol1way: iolock bit one-way set enable bit 1 = the iolock bit can only be set once (provided an unlocking sequence is executed); this prevents any possible future rp register changes 0 = the iolock bit can be set and cleared as needed (provided an unlocking sequence is executed)
pic18f97j94 family ds30575a-page 562 ? 2012 microchip technology inc. register 28-10: config6l: configuration register 6 low (byte address 30000ah) r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 wdps3 wdps2 wdps1 wdps0 wdtclk1 wdtclk0 wdtwin1 wdtwin0 bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 wdps<3:0>: watchdog timer postscale select bits 1111 = 1:32,768 1110 = 1:16,384 1101 = 1:8,192 1100 = 1:4,096 1011 = 1:2,048 1010 = 1:1,024 1001 = 1:512 1000 = 1:256 0111 = 1:128 0110 = 1:64 0101 = 1:32 0100 = 1:16 0011 = 1:8 0010 = 1:4 0001 = 1:2 0000 = 1:1 bit 3-2 wdtclk<1:0>: watchdog timer clock source bits 00 = use the peripheral clock when the system clock is not intosc/lprc and device is not in sleep; otherwise, use intosc/lprc 01 = always use sosc 10 = always use intosc/lprc 11 = use frc when windis = 0 , system clock is not intosc/lprc and device is not in sleep; otherwise, use intosc/lprc bit 1-0 wdtwin<1:0>: watchdog timer window width bits 11 = 25% 10 = 37.5% 01 = 50% 00 = 75%
? 2012 microchip technology inc. ds30575a-page 563 pic18f97j94 family register 28-11: config6h: configuration register 6 high (byte address 30000bh) u-1 u-1 u-1 u-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 ? ? ? ? wpsa windis wdten1 wdten0 bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: program the corresponding flash configuration bit to ? 1 ? bit 3 wpsa: wdt prescaler bit 1 = wdt prescaler ratio of 1:128 0 = wdt prescaler ratio of 1:32 bit 2 windis: windowed watchdog timer disable bit 1 = standard wdt is selected; windowed wdt is disabled 0 = windowed wdt is enabled when executing a clrwdt instruction while the wdt is disabled in hardware bit 1-0 wdten<1:0>: watchdog timer enable bits 11 = wdt is enabled in hardware 10 = wdt is controlled with the swdten bit setting 01 = wdt is enabled only while device is active and disabled in sleep; swdten bit is disabled 00 = wdt is disabled in hardware; swdten bit is disabled
pic18f97j94 family ds30575a-page 564 ? 2012 microchip technology inc. register 28-12: config7l: configuration register 7 low (byte address 30000ch) u-1 u-1 u-1 r/wo-1 r/wo-1 r/wo-1 u-1 r/wo-1 ? ? ? dsbiten dsboren vbtbor ? reten bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 1 ? bit 4 dsbiten: dsen bit enable bit 1 = deep sleep is controlled by the register bit, dsen 0 = deep sleep operation is always disabled bit 3 dsboren: deep sleep bor enable bit 1 = dsbor is enabled in deep sleep 0 = dsbor is disabled in deep sleep (does not affect operation in non-deep sleep modes) bit 2 vbtbor: v bat bor enable bit 1 = v bat bor is enabled 0 = v bat bor is disabled bit 1 unimplemented: read as ? 1 ? bit 0 reten : retention voltage regulator control enable bit 1 = retention voltage regulator is disabled 0 = retention voltage regulator is enabled; regulator power in sleep mode is controlled by sreten (rcon4<4>)
? 2012 microchip technology inc. ds30575a-page 565 pic18f97j94 family register 28-13: config8l: configuration register 8 low (byte address 30000eh) r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 u-1 u-1 u-1 dswdtps4 dswdtps3 dswdtps2 dswdtps1 dswdtps0 ? ? ? bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-3 dswdtps<4:0>: deep sleep watchdog timer postscale select bits the ds wdt prescaler is 32; this creates an approximate base time unit of 1 ms. 11111 = 1:2^ 36 (25.7 days) 11110 = 1:2^ 35 (12.8 days) 11101 = 1:2^ 34 (6.4 days) 11100 = 1:2^ 33 (77.0 hours) 11011 = 1:2^ 32 (38.5 hours) 11010 = 1:2^ 31 (19.2 hours) 11001 = 1:2^ 30 (9.6 hours) 11000 = 1:2^ 29 (4.8 hours) 10111 = 1:2^ 28 (2.4 hours) 10110 = 1:2^ 27 (72.2 minutes) 10101 = 1:2^ 26 (36.1 minutes) 10100 = 1:2^ 25 (18.0 minutes) 10011 = 1:2^ 24 (9.0 minutes) 10010 = 1:2^ 23 (4.5 minutes) 10001 = 1:2^ 22 (135.3s) 10000 = 1:2^ 21 (67.7s) 01111 = 1:2^ 20 (33.825s) 01110 = 1:2^ 19 (16.912s) 01101 = 1:2^ 18 (8.456s) 01100 = 1:2^ 17 (4.228s) 01011 = 1:65536 (2.114s) 01010 = 1:32768 (1.057s) 01001 = 1:16384 (528.5 ms) 01000 = 1:8192 (264.3 ms) 00111 = 1:4096 (132.1 ms) 00110 = 1:2048 (66.1 ms) 00101 = 1:1024 (33 ms) 00100 = 1:512 (16.5 ms) 00011 = 1:256 (8.3 ms) 00010 = 1:128 (4.1 ms) 00001 = 1:64 (2.1 ms) 00000 = 1:32 (1 ms) bit 2-0 unimplemented: read as ? 1 ?
pic18f97j94 family ds30575a-page 566 ? 2012 microchip technology inc. register 28-14: config8h: configuration register 8 high (byte address 30000fh) u-1 u-1 u-1 u-1 u-1 u-1 r/wo-1 r/wo-1 ? ? ? ? ? ? dswdtosc dswdten bit 7 bit 0 legend: p = programmable bit wo = write-once bit r = readable bit w = writable bit u = unimplemented bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: program the corresponding flash configuration bit to ? 1 ? bit 3-2 unimplemented: read as ? 1 ? bit 1 dswdtosc: dswdt reference clock select bit 1 = dswdt uses intosc/lprc as the reference clock 0 = dswdt uses t1osc/sosc as the reference clock bit 0 dswdten: deep sleep watchdog timer enable bit 1 = dswdt is enabled 0 = dswdt is disabled
? 2012 microchip technology inc. ds30575a-page 567 pic18f97j94 family register 28-15: devid2: device id register 2 for the pic18f97j94 rrrrrrrr dev10 dev9 dev8 dev7 dev6 dev5 dev4 dev3 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 dev<10:3>: device id bits these bits are used with the dev<2:0> bits in the device id register 1 to identify the part number. register 28-16: devid1: device id register 1 for the pic18f97j94 rrrrrrrr dev2 dev1 dev0 rev4 rev3 rev2 rev1 rev0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 dev<2:0>: device id bits these bits are used with the dev<10:3> bits in the device id register 2 to identify the part number: 0110 0010 101 = pic18f97j94 0110 0010 110 = pic18f96j99 0110 0010 111 = pic18f96j94 0110 0011 000 = pic18f95j94 0110 0011 001 = pic18f87j94 0110 0011 010 = pic18f86j99 0110 0011 011 = pic18f86j94 0110 0011 100 = pic18f85j94 0110 0011 101 = pic18f67j94 0110 0011 110 = pic18f66j99 0110 0011 111 = pic18f66j94 0110 0100 000 = PIC18F65J94 bit 4-0 rev<4:0>: revision id bits these bits are used to indicate the device revision.
pic18f97j94 family ds30575a-page 568 ? 2012 microchip technology inc. 28.2 watchdog timer (wdt) for the pic18f97j94 family of devices, the wdt is driven by the lf-intosc source. when the wdt is enabled, the clock source is also enabled. the nominal wdt period is 4 ms and has the same stability as the lf-intosc oscillator. the 4 ms period of the wdt is multiplied by a 16-bit postscaler. any output of the wdt postscaler is selected by a multiplexer, controlled by bits in configuration register 2h. available periods range from 4 ms to 4,194 seconds (about one hour). the wdt and postscaler are cleared when any of the following events occur: a sleep or clrwdt instruction is executed, the ircfx bits (osccon3<2:0>) are changed or a clock failure has occurred. 28.2.1 windowed operation the watchdog timer has an optional fixed window mode of operation. in this windowed mode, clrwdt instructions can only reset the wdt during the last 1/4 of the programmed wdt period. a clrwdt instruction executed before that window causes a wdt reset, similar to a wdt time-out. windowed wdt mode is enabled by programming the windis configuration bit (config6h<2>) to ? 0 ?. the wdt can be operated in one of four modes, as determined by wdten<1:0> (config6h<1:0>. the four modes are: ?wdt enabled ? wdt disabled ? wdt under software control, swdten (rcon2<5>) ?wdt: - enabled during normal operation - disabled during sleep figure 28-1: wdt block diagram note 1: the clrwdt and sleep instructions clear the wdt and postscaler counts when executed. 2: changing the setting of the ircfx bits (osccon3<2:0>) clear the wdt and postscaler counts. 3: when a clrwdt instruction is executed, the postscaler count will be cleared. intosc source wdt reset wdt counter enable wdt wdtps<3:0> clrwdt 4 reset all device resets sleep ? 128 change on ircfx bits intosc source enable wdt swdten wdten<1:0> wdten1 wdten0 wdt enabled, swdten disabled wdt controlled with swdten bit setting wdt enabled only while device active, disabled wdt disabled in hardware, swdten disabled wake-up from power-managed modes programmable postscaler 1:1 to 1:1,048,576
? 2012 microchip technology inc. ds30575a-page 569 pic18f97j94 family 28.2.2 control register register 28-17 shows the rcon2 register. this is a readable and writable register which contains a control bit that allows software to override the wdt enable configuration bit, but only if the configuration bit has disabled the wdt. register 28-17: rcon2: re set control register 2 r/w, hs-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 extr ( 1 ) ?swdten ( 2 ) ? ? ? ? ? bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 extr: external reset (mclr ) pin bit ( 1 ) 1 = a master clear (pin) reset has occurred 0 = a master clear (pin) reset has not occurred bit 6 unimplemented : read as ? 0 ? bit 5 swdten: software controlled watchdog timer enable bit ( 2 ) 1 = watchdog timer is on 0 = watchdog timer is off bit 4-0 unimplemented : read as ? 0 ? note 1: this bit is set in hardware; it can be cleared in software. 2: this bit has no effect unless the configuration bits, wdten<1:0> = 10 .
pic18f97j94 family ds30575a-page 570 ? 2012 microchip technology inc. 28.3 two-speed start-up the two-speed start-up feature helps to minimize the latency period from oscillator start-up to code execution by allowing the microcontroller to use the intosc (lf-intosc, mf-intosc, hf-intosc) oscillator as a clock source until the primary clock source is available. it is enabled by setting the ieso configuration bit. two-speed start-up should be enabled only if the pri- mary oscillator mode is lp, ms or hs (crystal-based modes). other sources do not require an ost start-up delay; for these, two-speed start-up should be disabled. when enabled, resets and wake-ups from sleep mode cause the device to configure itself to run from the internal oscillator block as the clock source, following the time-out of the power-up timer (pwrt) after a power- on reset is enabled. this allows almost immediate code execution while the primary oscillator starts and the ost is running. once the ost times out, the device automatically switches to pri_run mode. to use a higher clock speed on wake-up, the intosc or postscaler clock sources can be selected to provide a higher clock speed by setting bits, ircf<2:0>, immediately after reset. for wake-ups from sleep, the intosc or postscaler clock sources can be selected by setting the ircf2:0> bits prior to entering sleep mode. in all other power-managed modes, two-speed start-up is not used. the device will be clocked by the cur- rently selected clock source until the primary clock source becomes available. the setting of the ieso configuration bit is ignored. 28.3.1 special considerations for using two-speed start-up while using the intosc oscillator in two-speed start- up, the device still obeys the normal command sequences for entering power-managed modes, including multiple sleep instructions. in practice, this means that user code can change the nosc<2:0> bit settings or issue sleep instructions before the ost times out. this would allow an application to briefly wake-up, perform routine ?housekeeping? tasks and return to sleep before the device starts to operate from the primary oscillator. user code can also check if the primary clock source is currently providing the device clocking by checking the status of the cosc<2:0> bits (osccon<2:0>). if the bit is set, the primary oscillator is providing the clock. otherwise, the internal oscillator block is providing the clock during wake-up from reset or sleep mode. figure 28-2: timing transition for two-speed start-up (intosc to hspll) q1 q3 q4 osc1 peripheral program pc pc + 2 intosc pll clock q1 pc + 6 q2 output q3 q4 q1 cpu clock pc + 4 clock counter q2 q2 q3 note 1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. 2: clock transition typically occurs within 2-4 t osc . wake from interrupt event t pll (1) 12 n-1n clock ost expired transition (2) multiplexer t ost (1)
? 2012 microchip technology inc. ds30575a-page 571 pic18f97j94 family 28.4 fail-safe clock monitor the fail-safe clock monitor (fscm) allows the microcontroller to continue operation in the event of an external oscillator failure by automatically switch- ing the device clock to the internal oscillator block. the fscm function is enabled by clearing the fscmx configuration bits. when fscm is enabled, the lf-intosc oscillator runs at all times to monitor clocks to peripherals and provides a backup clock in the event of a clock failure. clock monitoring (shown in figure 28-3 ) is accom- plished by creating a sample clock signal, which is the output from the lf-intosc, divided by 64. this allows ample time between fscm sample clocks for a periph- eral clock edge to occur. the peripheral device clock and the sample clock are presented as inputs to the clock monitor (cm) latch. the cm is set on the falling edge of the device clock source, but cleared on the rising edge of the sample clock. figure 28-3: fscm block diagram clock failure is tested for on the falling edge of the sample clock. if a sample clock falling edge occurs while cm is still set, a clock failure has been detected ( figure 28-4 ). this causes the following: ? the fscm generates an oscillator fail interrupt by setting bit, oscfif (pir2<7>) ? the device clock source switches to the internal oscillator block (osccon is not updated to show the current clock source ? this is the fail-safe condition) ?the wdt is reset during switchover, the postscaler frequency from the internal oscillator block may not be sufficiently stable for timing-sensitive applications. in these cases, it may be desirable to select another clock configuration and enter an alternate power-managed mode. this can be done to attempt a partial recovery or execute a controlled shut- down. see section 28.3.1 ?special considerations for using two-speed start-up? for more details. to use a higher clock speed on wake-up, the intosc or postscaler clock sources can be selected to provide a higher clock speed by setting bits, ircf<2:0>, immediately after reset. for wake-ups from sleep, the intosc or postscaler clock sources can be selected by setting the ircf<2:0> bits prior to entering sleep mode. the fscm will detect only failures of the primary or secondary clock sources. if the internal oscillator block fails, no failure would be detected nor would any action be possible. 28.4.1 fscm and the watchdog timer both the fscm and the wdt are clocked by the intosc oscillator. since the wdt operates with a separate divider and counter, disabling the wdt has no effect on the operation of the intosc oscillator when the fscm is enabled. as already noted, the clock source is switched to the intosc clock when a clock failure is detected. depending on the frequency selected by the ircf<2:0> bits, this may mean a substantial change in the speed of code execution. if the wdt is enabled with a small prescale value, a decrease in clock speed allows a wdt time-out to occur and a subsequent device reset. for this reason, fail-safe clock events also reset the wdt and postscaler, allowing it to start timing from when execution speed was changed and decreasing the likelihood of an erroneous time-out. 28.4.2 exiting fail-safe operation the fail-safe condition is terminated by either a device reset or by entering a power-managed mode. on reset, the controller starts the primary clock source, specified in configuration register 1h (with any required start-up delays that are required for the oscillator mode, such as the ost or pll timer). the intosc multiplexer provides the device clock until the primary clock source becomes ready (similar to a two- speed start-up). the clock source is then switched to the primary clock automatically after an ost. the fail- safe clock monitor then resumes monitoring the peripheral clock. the primary clock source may never become ready during start-up. in this case, operation is clocked by the intosc multiplexer. the osccon register will remain in its reset state until a power-managed mode is entered. peripheral intosc 64 s c q (32 ? s) 488 hz (2.048 ms) clock monitor latch (cm) (edge-triggered) clock failure detected source clock q
pic18f97j94 family ds30575a-page 572 ? 2012 microchip technology inc. figure 28-4: fscm timing diagram 28.4.3 fscm interrupts in power-managed modes by entering a power-managed mode, the clock multi- plexer selects the clock source selected by the osccon register. fail-safe clock monitoring of the power- managed clock source resumes in the power-managed mode. if an oscillator failure occurs during power-managed operation, the subsequent events depend on whether or not the oscillator failure interrupt is enabled. if enabled (oscfif = 1 ), code execution will be clocked by the intosc multiplexer. an automatic transition back to the failed clock source will not occur. if the interrupt is disabled, subsequent interrupts while in idle mode will cause the cpu to begin executing instructions while being clocked by the intosc source. 28.4.4 por or wake from sleep the fscm is designed to detect oscillator failure at any point after the device has exited power-on reset (por) or low-power sleep mode. when the primary device clock is ec, rc or intosc modes, monitoring can begin immediately following these events. for oscillator modes involving a crystal or resonator (hs, hspll, lp or ms), the situation is somewhat different. since the oscillator may require a start-up time considerably longer than the fcsm sample clock time, a false clock failure may be detected. to prevent this, the internal oscillator block is automatically config- ured as the device clock and functions until the primary clock is stable (when the ost and pll timers have timed out). this is identical to two-speed start-up mode. once the primary clock is stable, the intosc returns to its role as the fscm source. as noted in section 28.3.1 ?special considerations for using two-speed start-up? , it is also possible to select another clock configuration and enter an alternate power-managed mode while waiting for the primary clock to become stable. when the new power- managed mode is selected, the primary clock is disabled. oscfif cm output device clock output sample clock failure detected oscillator failure note: the device clock is normally at a mu ch higher frequency than the sample clock. the relative frequencies in this example have been chosen for clarity. (q ) cm test cm test cm test note: the same logic that prevents false oscilla- tor failure interrupts on por, or wake from sleep, also prevents the detection of the oscillator?s failure to start at all following these events. this is avoided by an ost time-out condition and by using a timing routine to determine if the oscillator is tak- ing too long to start. even so, no oscillator failure interrupt will be flagged.
? 2012 microchip technology inc. ds30575a-page 573 pic18f97j94 family 28.4.5 program verification and code protection for all devices in the pic18f97j94 family of devices, the on-chip program memory space is treated as a single block. code protection for this block is controlled by one configuration bit, cp0. this bit inhibits external reads and writes to the program memory space. it has no direct effect in normal execution mode. 28.4.6 configuration register protection the configuration registers are protected against untoward changes or reads in two ways. the primary protection is the write-once feature of the configuration bits, which prevents reconfiguration once the bit has been programmed during a power cycle. to safeguard against unpredictable events, configuration bit changes, resulting from individual cell level disruptions (such as esd events), will cause a parity error and trigger a device reset. this is seen by the user as a configuration mismatch (cm) reset. the data for the configuration registers is derived from the fcw in program memory. when the cp0 bit is set, the source data for device configuration is also protected as a consequence. 28.5 in-circuit serial programming the pic18f97j94 family of devices can be serially programmed while in the end application circuit. this is simply done with two lines for clock and data and three other lines for power, ground and the programming voltage. this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or a custom firmware to be programmed. for the various programming modes, see the programming specification 28.6 in-circuit debugger when the debug configuration bit is programmed to a ? 0 ?, the in-circuit debugger functionality is enabled. this function allows simple debugging functions when used with mplab ? ide. when the microcontroller has this feature enabled, some resources are not available for general use. ta b l e 2 8 - 3 shows which resources are required by the background debugger. table 28-3: debugger resources to use the in-circuit debugger function of the microcon- troller, the design must implement in-circuit serial programming connections to mclr , v dd , v ss , rb7 and rb6. this will interface to the in-circuit debugger module available from microchip or one of the third-party development tool companies. i/o pins: rb6, rb7 stack: two levels program memory: 512 bytes data memory: 10 bytes
pic18f97j94 family ds30575a-page 574 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 575 pic18f97j94 family 29.0 instruction set summary the pic18f97j94 family of devices incorporates the standard set of 75 pic18 core instructions, as well as an extended set of 8 new instructions for the optimiza- tion of code that is recursive or that utilizes a software stack. the extended set is discussed later in this section. 29.1 standard instruction set the standard pic18 mcu instruction set adds many enhancements to the previous pic ? mcu instruction sets, while maintaining an easy migration from these pic mcu instruction sets. most instructions are a single program memory word (16 bits), but there are four instructions that require two program memory locations. each single-word instruction is a 16-bit word divided into an opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction. the instruction set is highly orthogonal and is grouped into four basic categories: ? byte-oriented operations ? bit-oriented operations ? literal operations ? control operations the pic18 instruction set summary in table 29-2 lists byte-oriented , bit-oriented , literal and control operations. table 29-1 shows the opcode field descriptions. most byte-oriented instructions have three operands: 1. the file register (specified by ?f?) 2. the destination of the result (specified by ?d?) 3. the accessed memory (specified by ?a?) the file register designator, ?f?, specifies which file reg- ister is to be used by the instruction. the destination designator, ?d?, specifies where the result of the operation is to be placed. if ?d? is zero, the result is placed in the wreg register. if ?d? is one, the result is placed in the file register specified in the instruction. all bit-oriented instructions have three operands: 1. the file register (specified by ?f?) 2. the bit in the file register (specified by ?b?) 3. the accessed memory (specified by ?a?) the bit field designator, ?b?, selects the number of the bit affected by the operation, while the file register desig- nator, ?f?, represents the number of the file in which the bit is located. the literal instructions may use some of the following operands: ? a literal value to be loaded into a file register (specified by ?k?) ? the desired fsr register to load the literal value into (specified by ?f?) ? no operand required (specified by ???) the control instructions may use some of the following operands: ? a program memory address (specified by ?n?) ? the mode of the call or return instructions (specified by ?s?) ? the mode of the table read and table write instructions (specified by ?m?) ? no operand required (specified by ???) all instructions are a single word, except for four double-word instructions. these instructions were made double-word to contain the required information in 32 bits. in the second word, the 4 msbs are ? 1 ?s. if this second word is executed as an instruction (by itself), it will execute as a nop . all single-word instructions are executed in a single instruction cycle, unless a conditional test is true or the program counter is changed as a result of the instruc- tion. in these cases, the execution takes two instruction cycles with the additional instruction cycle(s) executed as a nop . the double-word instructions execute in two instruction cycles. one instruction cycle consists of four oscillator periods. thus, for an oscillator frequency of 4 mhz, the normal instruction execution time is 1 ? s. if a conditional test is true, or the program counter is changed as a result of an instruction, the instruction execution time is 2 ? s. two-word branch instructions (if true) would take 3 ? s. figure 29-1 shows the general formats that the instruc- tions can have. all examples use the convention ?nnh? to represent a hexadecimal number. the instruction set summary, shown in ta bl e 2 9 -2 , lists the standard instructions recognized by the microchip mpasm tm assembler. section 29.1.1 ?standard instruction set? provides a description of each instruction.
pic18f97j94 family ds30575a-page 576 ? 2012 microchip technology inc. table 29-1: opcode field descriptions field description a ram access bit: a = 0 : ram location in access ram (bsr register is ignored) a = 1 : ram bank is specified by bsr register bbb bit address within an 8-bit file register (0 to 7). bsr bank select register. used to select the current ram bank. c, dc, z, ov, n alu status bits: c arry, d igit c arry, z ero, ov erflow, n egative. d destination select bit: d = 0 : store result in wreg d = 1 : store result in file register f dest destination: either the wreg register or the specified register file location. f 8-bit register file address (00h to ff h), or 2-bit fsr designator (0h to 3h). f s 12-bit register file address (000h to fffh). this is the source address. f d 12-bit register file address (000h to ff fh). this is the destination address. gie global interrupt enable bit. k literal field, constant data or label (may be either an 8-bit, 12-bit or a 20-bit value). label label name. mm the mode of the tblptr register for the table read and table write instructions. only used with table read and table write instructions: * no change to register (such as tblptr with table reads and writes) *+ post-increment register (such as tblptr with table reads and writes) *- post-decrement register (such as tblptr with table reads and writes) +* pre-increment register (such as tblptr with table reads and writes) n the relative address (2?s complement number) for relative branch instructions or the direct address for call/branch and return instructions. pc program counter. pcl program counter low byte. pch program counter high byte. pclath program counter high byte latch. pclatu program counter upper byte latch. pd power-down bit. prodh product of multiply high byte. prodl product of multiply low byte. s fast call/return mode select bit: s = 0 : do not update into/from shadow registers s = 1 : certain registers loaded into/from shadow registers (fast mode) tblptr 21-bit table pointer (points to a program memory location). tablat 8-bit table latch. to time-out bit. tos top-of-stack. u unused or unchanged. wdt watchdog timer. wreg working register (accumulator). x don?t care (? 0 ? or ? 1 ?). the assembler will generate code with x = 0 . it is the recommended form of use for compatibility with all microchip software tools. z s 7-bit offset value for indirect addressing of register files (source). z d 7-bit offset value for indirect addressing of register files (destination). { } optional argument. [text] indicates an indexed address. (text) the contents of text . [expr] specifies bit n of the register indicated by the pointer expr . ? assigned to. < > register bit field. ? in the set of. italics user-defined term (font is courier new).
? 2012 microchip technology inc. ds30575a-page 577 pic18f97j94 family figure 29-1: general format for instructions byte-oriented file register operations 15 10 9 8 7 0 d = 0 for result destination to be wreg register opcode d a f (file #) d = 1 for result destination to be file register (f) a = 0 to force access bank bit-oriented file register operations 15 12 11 9 8 7 0 opcode b (bit #) a f (file #) b = 3-bit position of bit in file register (f) literal operations 15 8 7 0 opcode k (literal) k = 8-bit immediate value byte to byte move operations (2-word) 15 12 11 0 opcode f (source file #) call , goto and branch operations 15 8 7 0 opcode n<7:0> (literal) n = 20-bit immediate value a = 1 for bsr to select bank f = 8-bit file register address a = 0 to force access bank a = 1 for bsr to select bank f = 8-bit file register address 15 12 11 0 1111 n<19:8> (literal) 15 12 11 0 1111 f (destination file #) f = 12-bit file register address control operations example instruction addwf myreg, w, b movff myreg1, myreg2 bsf myreg, bit, b movlw 7fh goto label 15 8 7 0 opcode s n<7:0> (literal) 15 12 11 0 1111 n<19:8> (literal) call myfunc 15 11 10 0 opcode n<10:0> (literal) s = fast bit bra myfunc 15 8 7 0 opcode n<7:0> (literal) bc myfunc
pic18f97j94 family ds30575a-page 578 ? 2012 microchip technology inc. table 29-2: pic18f97j94 family instruction set mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb byte-oriented operations addwf addwfc andwf clrf comf cpfseq cpfsgt cpfslt decf decfsz dcfsnz incf incfsz infsnz iorwf movf movff movwf mulwf negf rlcf rlncf rrcf rrncf setf subfwb subwf subwfb swapf tstfsz xorwf f, d, a f, d, a f, d, a f, a f, d, a f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f s , f d f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a add wreg and f add wreg and carry bit to f and wreg with f clear f complement f compare f with wreg, skip = compare f with wreg, skip > compare f with wreg, skip < decrement f decrement f, skip if 0 decrement f, skip if not 0 increment f increment f, skip if 0 increment f, skip if not 0 inclusive or wreg with f move f move f s (source) to 1st word f d (destination) 2nd word move wreg to f multiply wreg with f negate f rotate left f through carry rotate left f (no carry) rotate right f through carry rotate right f (no carry) set f subtract f from wreg with borrow subtract wreg from f subtract wreg from f with borrow swap nibbles in f test f, skip if 0 exclusive or wreg with f 1 1 1 1 1 1 (2 or 3) 1 (2 or 3) 1 (2 or 3) 1 1 (2 or 3) 1 (2 or 3) 1 1 (2 or 3) 1 (2 or 3) 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 (2 or 3) 1 0010 0010 0001 0110 0001 0110 0110 0110 0000 0010 0100 0010 0011 0100 0001 0101 1100 1111 0110 0000 0110 0011 0100 0011 0100 0110 0101 0101 0101 0011 0110 0001 01da 00da 01da 101a 11da 001a 010a 000a 01da 11da 11da 10da 11da 10da 00da 00da ffff ffff 111a 001a 110a 01da 01da 00da 00da 100a 01da 11da 10da 10da 011a 10da ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff c, dc, z, ov, n c, dc, z, ov, n z, n z z, n none none none c, dc, z, ov, n none none c, dc, z, ov, n none none z, n z, n none none none c, dc, z, ov, n c, z, n z, n c, z, n z, n none c, dc, z, ov, n c, dc, z, ov, n c, dc, z, ov, n none none z, n 1 , 2 1 , 2 1 , 2 2 1 , 2 4 4 1 , 2 1 , 2 , 3 , 4 1 , 2 , 3 , 4 1 , 2 1 , 2 , 3 , 4 4 1 , 2 1 , 2 1 1 , 2 1 , 2 1 , 2 1 , 2 4 1 , 2 note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and where applicable, d = 1 ), the prescaler will be cleared if assigned. 3: if the program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction.
? 2012 microchip technology inc. ds30575a-page 579 pic18f97j94 family bit-oriented operations bcf bsf btfsc btfss btg f, b, a f, b, a f, b, a f, b, a f, b, a bit clear f bit set f bit test f, skip if clear bit test f, skip if set bit toggle f 1 1 1 (2 or 3) 1 (2 or 3) 1 1001 1000 1011 1010 0111 bbba bbba bbba bbba bbba ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff none none none none none 1 , 2 1 , 2 3 , 4 3 , 4 1 , 2 control operations bc bn bnc bnn bnov bnz bov bra bz call clrwdt daw goto nop nop pop push rcall reset retfie retlw return sleep n n n n n n n n n n, s ? ? n ? ? ? ? n s k s ? branch if carry branch if negative branch if not carry branch if not negative branch if not overflow branch if not zero branch if overflow branch unconditionally branch if zero call subroutine 1st word 2nd word clear watchdog timer decimal adjust wreg go to address 1st word 2nd word no operation no operation pop top of return stack (tos) push top of return stack (tos) relative call software device reset return from interrupt enable return with literal in wreg return from subroutine go into standby mode 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 2 1 (2) 2 1 1 2 1 1 1 1 2 1 2 2 2 1 1110 1110 1110 1110 1110 1110 1110 1101 1110 1110 1111 0000 0000 1110 1111 0000 1111 0000 0000 1101 0000 0000 0000 0000 0000 0010 0110 0011 0111 0101 0001 0100 0nnn 0000 110s kkkk 0000 0000 1111 kkkk 0000 xxxx 0000 0000 1nnn 0000 0000 1100 0000 0000 nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk 0000 0000 kkkk kkkk 0000 xxxx 0000 0000 nnnn 1111 0001 kkkk 0001 0000 nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk 0100 0111 kkkk kkkk 0000 xxxx 0110 0101 nnnn 1111 000s kkkk 001s 0011 none none none none none none none none none none to , pd c none none none none none none all gie/gieh, peie/giel none none to , pd 4 table 29-2: pic18f97j94 family instruction set (continued) mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and where applicable, d = 1 ), the prescaler will be cleared if assigned. 3: if the program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction.
pic18f97j94 family ds30575a-page 580 ? 2012 microchip technology inc. literal operations addlw andlw iorlw lfsr movlb movlw mullw retlw sublw xorlw k k k f, k k k k k k k add literal and wreg and literal with wreg inclusive or literal with wreg move literal (12-bit) 2nd word to fsr(f) 1st word move literal to bsr<3:0> move literal to wreg multiply literal with wreg return with literal in wreg subtract wreg from literal exclusive or literal with wreg 1 1 1 2 1 1 1 2 1 1 0000 0000 0000 1110 1111 0000 0000 0000 0000 0000 0000 1111 1011 1001 1110 0000 0001 1110 1101 1100 1000 1010 kkkk kkkk kkkk 00ff kkkk 0000 kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk c, dc, z, ov, n z, n z, n none none none none none c, dc, z, ov, n z, n data memory ? program memory operations tblrd* tblrd*+ tblrd*- tblrd+* tblwt* tblwt*+ tblwt*- tblwt+* table read table read with post-increment table read with post-decrement table read with pre-increment table write table write with post-increment table write with post-decrement table write with pre-increment 2 2 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1000 1001 1010 1011 1100 1101 1110 1111 none none none none none none none none table 29-2: pic18f97j94 family instruction set (continued) mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and where applicable, d = 1 ), the prescaler will be cleared if assigned. 3: if the program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction.
? 2012 microchip technology inc. ds30575a-page 581 pic18f97j94 family 29.1.1 standard instruction set addlw add literal to w syntax: addlw k operands: 0 ? k ? 255 operation: (w) + k ? w status affected: n, ov, c, dc, z encoding: 0000 1111 kkkk kkkk description: the contents of w are added to the 8-bit literal ?k? and the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: addlw 15h before instruction w = 10h after instruction w = 25h addwf add w to f syntax: addwf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (w) + (f) ? dest status affected: n, ov, c, dc, z encoding: 0010 01da ffff ffff description: add w to register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: addwf reg, 0, 0 before instruction w = 17h reg = 0c2h after instruction w = 0d9h reg = 0c2h note: all pic18 instructions may take an optional label argument preceding the instruction mnemonic for use in symbolic addressing. if a label is used, the instruction format then becomes: {label} instruction argument(s).
pic18f97j94 family ds30575a-page 582 ? 2012 microchip technology inc. addwfc add w and carry bit to f syntax: addwfc f {,d {,a}} operands: 0 ? f ? 255 d ?? [0,1] a ?? [0,1] operation: (w) + (f) + (c) ? dest status affected: n,ov, c, dc, z encoding: 0010 00da ffff ffff description: add w, the carry flag and data memory location ?f?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed in data memory location ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: addwfc reg, 0, 1 before instruction carry bit = 1 reg = 02h w=4dh after instruction carry bit = 0 reg = 02h w = 50h andlw and literal with w syntax: andlw k operands: 0 ? k ? 255 operation: (w) .and. k ? w status affected: n, z encoding: 0000 1011 kkkk kkkk description: the contents of w are anded with the 8-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: andlw 05fh before instruction w=a3h after instruction w = 03h
? 2012 microchip technology inc. ds30575a-page 583 pic18f97j94 family andwf and w with f syntax: andwf f {,d {,a}} operands: 0 ? f ? 255 d ?? [0,1] a ?? [0,1] operation: (w) .and. (f) ? dest status affected: n, z encoding: 0001 01da ffff ffff description: the contents of w are anded with register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: andwf reg, 0, 0 before instruction w = 17h reg = c2h after instruction w = 02h reg = c2h bc branch if carry syntax: bc n operands: -128 ? n ? 127 operation: if carry bit is ? 1 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0010 nnnn nnnn description: if the carry bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bc 5 before instruction pc = address (here) after instruction if carry = 1 ; pc = address (here + 12) if carry = 0 ; pc = address (here + 2)
pic18f97j94 family ds30575a-page 584 ? 2012 microchip technology inc. bcf bit clear f syntax: bcf f, b {,a} operands: 0 ? f ? 255 0 ? b ? 7 a ?? [0,1] operation: 0 ? f status affected: none encoding: 1001 bbba ffff ffff description: bit ?b? in register ?f? is cleared. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: bcf flag_reg, 7, 0 before instruction flag_reg = c7h after instruction flag_reg = 47h bn branch if negative syntax: bn n operands: -128 ? n ? 127 operation: if negative bit is ? 1 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0110 nnnn nnnn description: if the negative bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bn jump before instruction pc = address (here) after instruction if negative = 1 ; pc = address (jump) if negative = 0 ; pc = address (here + 2)
? 2012 microchip technology inc. ds30575a-page 585 pic18f97j94 family bnc branch if not carry syntax: bnc n operands: -128 ? n ? 127 operation: if carry bit is ? 0 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0011 nnnn nnnn description: if the carry bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnc jump before instruction pc = address (here) after instruction if carry = 0 ; pc = address (jump) if carry = 1 ; pc = address (here + 2) bnn branch if not negative syntax: bnn n operands: -128 ? n ? 127 operation: if negative bit is ? 0 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0111 nnnn nnnn description: if the negative bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnn jump before instruction pc = address (here) after instruction if negative = 0 ; pc = address (jump) if negative = 1 ; pc = address (here + 2)
pic18f97j94 family ds30575a-page 586 ? 2012 microchip technology inc. bnov branch if not overflow syntax: bnov n operands: -128 ? n ? 127 operation: if overflow bit is ? 0 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0101 nnnn nnnn description: if the overflow bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnov jump before instruction pc = address (here) after instruction if overflow = 0 ; pc = address (jump) if overflow = 1 ; pc = address (here + 2) bnz branch if not zero syntax: bnz n operands: -128 ? n ? 127 operation: if zero bit is ? 0 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0001 nnnn nnnn description: if the zero bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnz jump before instruction pc = address (here) after instruction if zero = 0 ; pc = address (jump) if zero = 1 ; pc = address (here + 2)
? 2012 microchip technology inc. ds30575a-page 587 pic18f97j94 family bra unconditional branch syntax: bra n operands: -1024 ? n ? 1023 operation: (pc) + 2 + 2n ? pc status affected: none encoding: 1101 0nnn nnnn nnnn description: add the 2?s complement number ?2n? to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is a two-cycle instruction. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation example: here bra jump before instruction pc = address (here) after instruction pc = address (jump) bsf bit set f syntax: bsf f, b {,a} operands: 0 ? f ? 255 0 ? b ? 7 a ?? [0,1] operation: 1 ? f status affected: none encoding: 1000 bbba ffff ffff description: bit ?b? in register ?f? is set. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: bsf flag_reg, 7, 1 before instruction flag_reg = 0ah after instruction flag_reg = 8ah
pic18f97j94 family ds30575a-page 588 ? 2012 microchip technology inc. btfsc bit test file, skip if clear syntax: btfsc f, b {,a} operands: 0 ? f ? 255 0 ? b ? 7 a ?? [0,1] operation: skip if (f) = 0 status affected: none encoding: 1011 bbba ffff ffff description: if bit ?b? in register ?f? is ? 0 ?, then the next instruction is skipped. if bit ?b? is ? 0 ?, then the next instruction fetched during the current instruction execution is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here false true btfsc : : flag, 1, 0 before instruction pc = address (here) after instruction if flag<1> = 0 ; pc = address (true) if flag<1> = 1 ; pc = address (false) btfss bit test file, skip if set syntax: btfss f, b {,a} operands: 0 ? f ? 255 0 ? b < 7 a ?? [0,1] operation: skip if (f) = 1 status affected: none encoding: 1010 bbba ffff ffff description: if bit ?b? in register ?f? is ? 1 ?, then the next instruction is skipped. if bit ?b? is ? 1 ?, then the next instruction fetched during the current instruction execution is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here false true btfss : : flag, 1, 0 before instruction pc = address (here) after instruction if flag<1> = 0 ; pc = address (false) if flag<1> = 1 ; pc = address (true)
? 2012 microchip technology inc. ds30575a-page 589 pic18f97j94 family btg bit toggle f syntax: btg f, b {,a} operands: 0 ? f ? 255 0 ? b < 7 a ?? [0,1] operation: (f ) ? f status affected: none encoding: 0111 bbba ffff ffff description: bit ?b? in data memory location, ?f?, is inverted. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: btg portc, 4, 0 before instruction: portc = 0111 0101 [75h] after instruction: portc = 0110 0101 [65h] bov branch if overflow syntax: bov n operands: -128 ? n ? 127 operation: if overflow bit is ? 1 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0100 nnnn nnnn description: if the overflow bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bov jump before instruction pc = address (here) after instruction if overflow = 1 ; pc = address (jump) if overflow = 0 ; pc = address (here + 2)
pic18f97j94 family ds30575a-page 590 ? 2012 microchip technology inc. bz branch if zero syntax: bz n operands: -128 ? n ? 127 operation: if zero bit is ? 1 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0000 nnnn nnnn description: if the zero bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bz jump before instruction pc = address (here) after instruction if zero = 1 ; pc = address (jump) if zero = 0 ; pc = address (here + 2) call subroutine call syntax: call k {,s} operands: 0 ? k ? 1048575 s ?? [0,1] operation: (pc) + 4 ? tos, k ? pc<20:1>; if s = 1 (w) ? ws, (status) ? statuss, (bsr) ? bsrs status affected: none encoding: 1st word (k<7:0>) 2nd word(k<19:8>) 1110 1111 110s k 19 kkk k 7 kkk kkkk kkkk 0 kkkk 8 description: subroutine call of entire 2-mbyte memory range. first, return address (pc+ 4) is pushed onto the return stack. if ?s? = 1 , the w, status and bsr registers are also pushed into their respective shadow registers, ws, statuss and bsrs. if ?s? = 0 , no update occurs. then, the 20-bit value ?k? is loaded into pc<20:1>. call is a two-cycle instruction. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k?<7:0>, push pc to stack read literal ?k?<19:8>, write to pc no operation no operation no operation no operation example: here call there,1 before instruction pc = address (here) after instruction pc = address (there) tos = address (here + 4) ws = w bsrs = bsr statuss = status
? 2012 microchip technology inc. ds30575a-page 591 pic18f97j94 family clrf clear f syntax: clrf f {,a} operands: 0 ? f ? 255 a ?? [0,1] operation: 000h ? f, 1 ? z status affected: z encoding: 0110 101a ffff ffff description: clears the contents of the specified register. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: clrf flag_reg,1 before instruction flag_reg = 5ah after instruction flag_reg = 00h clrwdt clear watchdog timer syntax: clrwdt operands: none operation: 000h ? wdt, 000h ? wdt postscaler, 1 ? to , 1 ? pd status affected: to , pd encoding: 0000 0000 0000 0100 description: clrwdt instruction resets the watchdog timer. it also resets the post- scaler of the wdt. status bits, to and pd , are set. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation process data no operation example: clrwdt before instruction wdt counter = ? after instruction wdt counter = 00h wdt postscaler = 0 to = 1 pd = 1
pic18f97j94 family ds30575a-page 592 ? 2012 microchip technology inc. comf complement f syntax: comf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: f ? dest status affected: n, z encoding: 0001 11da ffff ffff description: the contents of register ?f? are complemented. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: comf reg, 0, 0 before instruction reg = 13h after instruction reg = 13h w=ech cpfseq compare f with w, skip if f = w syntax: cpfseq f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: (f) ? (w), skip if (f) = (w) (unsigned comparison) status affected: none encoding: 0110 001a ffff ffff description: compares the contents of data memory location ?f? to the contents of w by performing an unsigned subtraction. if ?f? = w , then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfseq reg, 0 nequal : equal : before instruction pc address = here w=? reg = ? after instruction if reg = w; pc = address (equal) if reg ? w; pc = address (nequal)
? 2012 microchip technology inc. ds30575a-page 593 pic18f97j94 family cpfsgt compare f with w, skip if f > w syntax: cpfsgt f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: (f) ? ?? w), skip if (f) > (w) (unsigned comparison) status affected: none encoding: 0110 010a ffff ffff description: compares the contents of data memory location ?f? to the contents of the w by performing an unsigned subtraction. if the contents of ?f? are greater than the contents of wreg , then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfsgt reg, 0 ngreater : greater : before instruction pc = address (here) w= ? after instruction if reg ? w; pc = address (greater) if reg ? w; pc = address (ngreater) cpfslt compare f with w, skip if f < w syntax: cpfslt f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: (f) ? ?? w), skip if (f) < (w) (unsigned comparison) status affected: none encoding: 0110 000a ffff ffff description: compares the contents of data memory location ?f? to the contents of w by performing an unsigned subtraction. if the contents of ?f? are less than the contents of w, then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfslt reg, 1 nless : less : before instruction pc = address (here) w= ? after instruction if reg < w; pc = address (less) if reg ? w; pc = address (nless)
pic18f97j94 family ds30575a-page 594 ? 2012 microchip technology inc. daw decimal adjust w register syntax: daw operands: none operation: if [w<3:0> > 9] or [dc = 1 ], then (w<3:0>) + 6 ? w<3:0>; else (w<3:0>) ? w<3:0> if [w<7:4> > 9] or [c = 1 ], then (w<7:4>) + 6 ? w<7:4>; c = ? 1 ; else (w<7:4>) ? w<7:4> status affected: c encoding: 0000 0000 0000 0111 description: daw adjusts the 8-bit value in w, resulting from the earlier addition of two variables (each in packed bcd format) and produces a correct packed bcd result. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register w process data write w example 1: daw before instruction w=a5h c= 0 dc = 0 after instruction w = 05h c= 1 dc = 0 example 2: before instruction w=ceh c= 0 dc = 0 after instruction w = 34h c= 1 dc = 0 decf decrement f syntax: decf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? 1 ? dest status affected: c, dc, n, ov, z encoding: 0000 01da ffff ffff description: decrement register, ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: decf cnt, 1, 0 before instruction cnt = 01h z= 0 after instruction cnt = 00h z= 1
? 2012 microchip technology inc. ds30575a-page 595 pic18f97j94 family decfsz decrement f, skip if 0 syntax: decfsz f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? 1 ? dest, skip if result = 0 status affected: none encoding: 0010 11da ffff ffff description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f?. if the result is ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here decfsz cnt, 1, 1 goto loop continue before instruction pc = address (here) after instruction cnt = cnt ? 1 if cnt = 0 ; pc = address (continue) if cnt ? 0 ; pc = address (here + 2) dcfsnz decrement f, skip if not 0 syntax: dcfsnz f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? 1 ? dest, skip if result ? 0 status affected: none encoding: 0100 11da ffff ffff description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f?. if the result is not ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here dcfsnz temp, 1, 0 zero : nzero : before instruction temp = ? after instruction temp = temp ? 1, if temp = 0 ; pc = address (zero) if temp ? 0 ; pc = address (nzero)
pic18f97j94 family ds30575a-page 596 ? 2012 microchip technology inc. goto unconditional branch syntax: goto k operands: 0 ? k ? 1048575 operation: k ? pc<20:1> status affected: none encoding: 1st word (k<7:0>) 2nd word(k<19:8>) 1110 1111 1111 k 19 kkk k 7 kkk kkkk kkkk 0 kkkk 8 description: goto allows an unconditional branch anywhere within entire 2-mbyte memory range. the 20-bit value ?k? is loaded into pc<20:1>. goto is always a two-cycle instruction. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k?<7:0>, no operation read literal ?k?<19:8>, write to pc no operation no operation no operation no operation example: goto there after instruction pc = address (there) incf increment f syntax: incf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) + 1 ? dest status affected: c, dc, n, ov, z encoding: 0010 10da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: incf cnt, 1, 0 before instruction cnt = ffh z= 0 c=? dc = ? after instruction cnt = 00h z= 1 c= 1 dc = 1
? 2012 microchip technology inc. ds30575a-page 597 pic18f97j94 family incfsz increment f, skip if 0 syntax: incfsz f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) + 1 ? dest, skip if result = 0 status affected: none encoding: 0011 11da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f?. if the result is ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here incfsz cnt, 1, 0 nzero : zero : before instruction pc = address (here) after instruction cnt = cnt + 1 if cnt = 0 ; pc = address (zero) if cnt ? 0 ; pc = address (nzero) infsnz increment f, skip if not 0 syntax: infsnz f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) + 1 ? dest, skip if result ? 0 status affected: none encoding: 0100 10da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f?. if the result is not ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here infsnz reg, 1, 0 zero nzero before instruction pc = address (here) after instruction reg = reg + 1 if reg ? 0 ; pc = address (nzero) if reg = 0 ; pc = address (zero)
pic18f97j94 family ds30575a-page 598 ? 2012 microchip technology inc. iorlw inclusive or literal with w syntax: iorlw k operands: 0 ? k ? 255 operation: (w) .or. k ? w status affected: n, z encoding: 0000 1001 kkkk kkkk description: the contents of w are ored with the eight-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: iorlw 35h before instruction w=9ah after instruction w=bfh iorwf inclusive or w with f syntax: iorwf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (w) .or. (f) ? dest status affected: n, z encoding: 0001 00da ffff ffff description: inclusive or w with register ?f?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: iorwf result, 0, 1 before instruction result = 13h w = 91h after instruction result = 13h w = 93h
? 2012 microchip technology inc. ds30575a-page 599 pic18f97j94 family lfsr load fsr syntax: lfsr f, k operands: 0 ? f ? 2 0 ? k ? 4095 operation: k ? fsrf status affected: none encoding: 1110 1111 1110 0000 00ff k 7 kkk k 11 kkk kkkk description: the 12-bit literal ?k? is loaded into the file select register pointed to by ?f?. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? msb process data write literal ?k? msb to fsrfh decode read literal ?k? lsb process data write literal ?k? to fsrfl example: lfsr 2, 3abh after instruction fsr2h = 03h fsr2l = abh movf move f syntax: movf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: f ? dest status affected: n, z encoding: 0101 00da ffff ffff description: the contents of register ?f? are moved to a destination dependent upon the status of ?d?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f?. location ?f? can be anywhere in the 256-byte bank. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write w example: movf reg, 0, 0 before instruction reg = 22h w=ffh after instruction reg = 22h w = 22h
pic18f97j94 family ds30575a-page 600 ? 2012 microchip technology inc. movff move f to f syntax: movff f s ,f d operands: 0 ? f s ? 4095 0 ? f d ? 4095 operation: (f s ) ? f d status affected: none encoding: 1st word (source) 2nd word (destin.) 1100 1111 ffff ffff ffff ffff ffff s ffff d description: the contents of source register, ?f s ?, are moved to destination register ?f d ?. location of source ?f s ? can be anywhere in the 4096-byte data space (000h to fffh) and location of destination ?f d ? can also be anywhere from 000h to fffh. either source or destination can be w (a useful special situation). movff is particularly useful for transferring a data memory location to a peripheral register (such as the transmit buffer or an i/o port). the movff instruction cannot use the pcl, tosu, tosh or tosl as the destination register words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read register ?f? (src) process data no operation decode no operation no dummy read no operation write register ?f? (dest) example: movff reg1, reg2 before instruction reg1 = 33h reg2 = 11h after instruction reg1 = 33h reg2 = 33h movlb move literal to low nibble in bsr syntax: movlb k operands: 0 ? k ? 255 operation: k ? bsr status affected: none encoding: 0000 0001 kkkk kkkk description: the eight-bit literal ?k? is loaded into the bank select register (bsr). the value of bsr<7:4> always remains ? 0 ? regardless of the value of k 7 :k 4 . words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write literal ?k? to bsr example: movlb 5 before instruction bsr register = 02h after instruction bsr register = 05h
? 2012 microchip technology inc. ds30575a-page 601 pic18f97j94 family movlw move literal to w syntax: movlw k operands: 0 ? k ? 255 operation: k ? w status affected: none encoding: 0000 1110 kkkk kkkk description: the eight-bit literal ?k? is loaded into w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: movlw 5ah after instruction w=5ah movwf move w to f syntax: movwf f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: (w) ? f status affected: none encoding: 0110 111a ffff ffff description: move data from w to register ?f?. location ?f? can be anywhere in the 256-byte bank. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: movwf reg, 0 before instruction w=4fh reg = ffh after instruction w=4fh reg = 4fh
pic18f97j94 family ds30575a-page 602 ? 2012 microchip technology inc. mullw multiply literal with w syntax: mullw k operands: 0 ? k ? 255 operation: (w) x k ? prodh:prodl status affected: none encoding: 0000 1101 kkkk kkkk description: an unsigned multiplication is carried out between the contents of w and the 8-bit literal ?k?. the 16-bit result is placed in the prodh:prodl register pair. prodh contains the high byte. w is unchanged. none of the status flags are affected. note that neither overflow nor carry is possible in this operation. a zero result is possible but not detected. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write registers prodh: prodl example: mullw 0c4h before instruction w=e2h prodh = ? prodl = ? after instruction w=e2h prodh = adh prodl = 08h mulwf multiply w with f syntax: mulwf f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: (w) x (f) ? prodh:prodl status affected: none encoding: 0000 001a ffff ffff description: an unsigned multiplication is carried out between the contents of w and the register file location ?f?. the 16-bit result is stored in the prodh:prodl register pair. prodh contains the high byte. both w and ?f? are unchanged. none of the status flags are affected. note that neither overflow nor carry is possible in this operation. a zero result is possible but not detected. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write registers prodh: prodl example: mulwf reg, 1 before instruction w=c4h reg = b5h prodh = ? prodl = ? after instruction w=c4h reg = b5h prodh = 8ah prodl = 94h
? 2012 microchip technology inc. ds30575a-page 603 pic18f97j94 family negf negate f syntax: negf f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: (f ) + 1 ? f status affected: n, ov, c, dc, z encoding: 0110 110a ffff ffff description: location ?f? is negated using two?s complement. the result is placed in the data memory location ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: negf reg, 1 before instruction reg = 0011 1010 [3ah] after instruction reg = 1100 0110 [c6h] nop no operation syntax: nop operands: none operation: no operation status affected: none encoding: 0000 1111 0000 xxxx 0000 xxxx 0000 xxxx description: no operation. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation example: none.
pic18f97j94 family ds30575a-page 604 ? 2012 microchip technology inc. pop pop top of return stack syntax: pop operands: none operation: (tos) ? bit bucket status affected: none encoding: 0000 0000 0000 0110 description: the tos value is pulled off the return stack and is discarded. the tos value then becomes the previous value that was pushed onto the return stack. this instruction is provided to enable the user to properly manage the return stack to incorporate a software stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation pop tos value no operation example: pop goto new before instruction tos = 0031a2h stack (1 level down) = 014332h after instruction tos = 014332h pc = new push push top of return stack syntax: push operands: none operation: (pc + 2) ? tos status affected: none encoding: 0000 0000 0000 0101 description: the pc + 2 is pushed onto the top of the return stack. the previous tos value is pushed down on the stack. this instruction allows implementing a software stack by modifying tos and then pushing it onto the return stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode push pc + 2 onto return stack no operation no operation example: push before instruction tos = 345ah pc = 0124h after instruction pc = 0126h tos = 0126h stack (1 level down) = 345ah
? 2012 microchip technology inc. ds30575a-page 605 pic18f97j94 family rcall relative call syntax: rcall n operands: -1024 ? n ? 1023 operation: (pc) + 2 ? tos, (pc) + 2 + 2n ? pc status affected: none encoding: 1101 1nnn nnnn nnnn description: subroutine call with a jump up to 1k from the current location. first, return address (pc + 2) is pushed onto the stack. then, add the 2?s complement number ?2n? to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is a two-cycle instruction. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?n? push pc to stack process data write to pc no operation no operation no operation no operation example: here rcall jump before instruction pc = address (here) after instruction pc = address (jump) tos = address (here + 2) reset reset syntax: reset operands: none operation: reset all registers and flags that are affected by a mclr reset. status affected: all encoding: 0000 0000 1111 1111 description: this instruction provides a way to execute a mclr reset in software. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode start reset no operation no operation example: reset after instruction registers = reset value flags* = reset value
pic18f97j94 family ds30575a-page 606 ? 2012 microchip technology inc. retfie return from interrupt syntax: retfie {s} operands: s ? [0,1] operation: (tos) ? pc, 1 ? gie/gieh or peie/giel; if s = 1 , (ws) ? w, (statuss) ? status, (bsrs) ? bsr, pclatu, pclath are unchanged status affected: gie/gieh, peie/giel. encoding: 0000 0000 0001 000s description: return from interrupt. stack is popped and top-of-stack (tos) is loaded into the pc. interrupts are enabled by setting either the high or low-priority global interrupt enable bit. if ?s? = 1 , the contents of the shadow registers ws, statuss and bsrs are loaded into their corresponding registers w, status and bsr. if ?s? = 0 , no update of these registers occurs. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation pop pc from stack set gieh or giel no operation no operation no operation no operation example: retfie 1 after interrupt pc = tos w=ws bsr = bsrs status = statuss gie/gieh, peie/giel = 1 retlw return literal to w syntax: retlw k operands: 0 ? k ? 255 operation: k ? w, (tos) ? pc, pclatu, pclath are unchanged status affected: none encoding: 0000 1100 kkkk kkkk description: w is loaded with the 8-bit literal ?k?. the program counter is loaded from the top of the stack (the return address). the high address latch (pclath) remains unchanged. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data pop pc from stack, write to w no operation no operation no operation no operation example: call table ; w contains table ; offset value ; w now has ; table value : table addwf pcl ; w = offset retlw k0 ; begin table retlw k1 ; : : retlw kn ; end of table before instruction w = 07h after instruction w = value of kn
? 2012 microchip technology inc. ds30575a-page 607 pic18f97j94 family return return from subroutine syntax: return {s} operands: s ? [0,1] operation: (tos) ? pc; if s = 1 , (ws) ? w, (statuss) ? status, (bsrs) ? bsr, pclatu, pclath are unchanged status affected: none encoding: 0000 0000 0001 001s description: return from subroutine. the stack is popped and the top of the stack (tos) is loaded into the program counter. if ?s?= 1 , the contents of the shadow registers ws, statuss and bsrs are loaded into their corresponding registers w, status and bsr. if ?s? = 0 , no update of these registers occurs. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation process data pop pc from stack no operation no operation no operation no operation example: return after instruction: pc = tos rlcf rotate left f through carry syntax: rlcf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? dest, (f<7>) ? c, (c) ? dest<0> status affected: c, n, z encoding: 0011 01da ffff ffff description: the contents of register ?f? are rotated one bit to the left through the carry flag. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is stored back in register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rlcf reg, 0, 0 before instruction reg = 1110 0110 c= 0 after instruction reg = 1110 0110 w= 1100 1100 c= 1 c register f
pic18f97j94 family ds30575a-page 608 ? 2012 microchip technology inc. rlncf rotate left f (no carry) syntax: rlncf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? dest, (f<7>) ? dest<0> status affected: n, z encoding: 0100 01da ffff ffff description: the contents of register ?f? are rotated one bit to the left. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is stored back in register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rlncf reg, 1, 0 before instruction reg = 1010 1011 after instruction reg = 0101 0111 register f rrcf rotate right f through carry syntax: rrcf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? dest, (f<0>) ? c, (c) ? dest<7> status affected: c, n, z encoding: 0011 00da ffff ffff description: the contents of register ?f? are rotated one bit to the right through the carry flag. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rrcf reg, 0, 0 before instruction reg = 1110 0110 c= 0 after instruction reg = 1110 0110 w= 0111 0011 c= 0 c register f
? 2012 microchip technology inc. ds30575a-page 609 pic18f97j94 family rrncf rotate right f (no carry) syntax: rrncf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? dest, (f<0>) ? dest<7> status affected: n, z encoding: 0100 00da ffff ffff description: the contents of register ?f? are rotated one bit to the right. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f?. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: rrncf reg, 1, 0 before instruction reg = 1101 0111 after instruction reg = 1110 1011 example 2: rrncf reg, 0, 0 before instruction w=? reg = 1101 0111 after instruction w= 1110 1011 reg = 1101 0111 register f setf set f syntax: setf f {,a} operands: 0 ? f ? 255 a ?? [0,1] operation: ffh ? f status affected: none encoding: 0110 100a ffff ffff description: the contents of the specified register are set to ffh. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: setf reg,1 before instruction reg = 5ah after instruction reg = ffh
pic18f97j94 family ds30575a-page 610 ? 2012 microchip technology inc. sleep enter sleep mode syntax: sleep operands: none operation: 00h ? wdt, 0 ? wdt postscaler, 1 ? to , 0 ? pd status affected: to , pd encoding: 0000 0000 0000 0011 description: the power-down status bit (pd ) is cleared. the time-out status bit (to ) is set. the watchdog timer and its postscaler are cleared. the processor is put into sleep mode with the oscillator stopped. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation process data go to sleep example: sleep before instruction to =? pd =? after instruction to = 1 ? pd = 0 ? if wdt causes wake-up, this bit is cleared. subfwb subtract f from w with borrow syntax: subfwb f {,d {,a}} operands: 0 ?? f ?? 255 d ? [0,1] a ? [0,1] operation: (w) ? (f) ? (c ) ?? dest status affected: n, ov, c, dc, z encoding: 0101 01da ffff ffff description: subtract register ?f? and carry flag (borrow) from w (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored in register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subfwb reg, 1, 0 before instruction reg = 3 w=2 c=1 after instruction reg = ff w=2 c=0 z=0 n = 1 ; result is negative example 2: subfwb reg, 0, 0 before instruction reg = 2 w=5 c=1 after instruction reg = 2 w=3 c=1 z=0 n = 0 ; result is positive example 3: subfwb reg, 1, 0 before instruction reg = 1 w=2 c=0 after instruction reg = 0 w=2 c=1 z = 1 ; result is zero n=0
? 2012 microchip technology inc. ds30575a-page 611 pic18f97j94 family sublw subtract w from literal syntax: sublw k operands: 0 ?? k ?? 255 operation: k ? (w) ?? w status affected: n, ov, c, dc, z encoding: 0000 1000 kkkk kkkk description: w is subtracted from the eight-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example 1: sublw 02h before instruction w = 01h c=? after instruction w = 01h c= 1 ; result is positive z= 0 n= 0 example 2: sublw 02h before instruction w = 02h c=? after instruction w = 00h c= 1 ; result is zero z= 1 n= 0 example 3: sublw 02h before instruction w = 03h c=? after instruction w = ffh ; (2?s complement) c= 0 ; result is negative z= 0 n= 1 subwf subtract w from f syntax: subwf f {,d {,a}} operands: 0 ?? f ?? 255 d ? [0,1] a ? [0,1] operation: (f) ? (w) ?? dest status affected: n, ov, c, dc, z encoding: 0101 11da ffff ffff description: subtract w from register ?f? (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subwf reg, 1, 0 before instruction reg = 3 w=2 c=? after instruction reg = 1 w=2 c = 1 ; result is positive z=0 n=0 example 2: subwf reg, 0, 0 before instruction reg = 2 w=2 c=? after instruction reg = 2 w=0 c = 1 ; result is zero z=1 n=0 example 3: subwf reg, 1, 0 before instruction reg = 1 w=2 c=? after instruction reg = ffh ;(2?s complement) w=2 c = 0 ; result is negative z=0 n=1
pic18f97j94 family ds30575a-page 612 ? 2012 microchip technology inc. subwfb subtract w from f with borrow syntax: subwfb f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? (w) ? (c ) ?? dest status affected: n, ov, c, dc, z encoding: 0101 10da ffff ffff description: subtract w and the carry flag (borrow) from register ?f? (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addr essing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subwfb reg, 1, 0 before instruction reg = 19h (0001 1001) w=0dh (0000 1101) c= 1 after instruction reg = 0ch (0000 1011) w=0dh (0000 1101) c= 1 z= 0 n= 0 ; result is positive example 2: subwfb reg, 0, 0 before instruction reg = 1bh (0001 1011) w=1ah (0001 1010) c= 0 after instruction reg = 1bh (0001 1011) w = 00h c= 1 z= 1 ; result is zero n= 0 example 3: subwfb reg, 1, 0 before instruction reg = 03h (0000 0011) w=0eh (0000 1101) c= 1 after instruction reg = f5h (1111 0100) ; [2?s comp] w=0eh (0000 1101) c= 0 z= 0 n= 1 ; result is negative swapf swap f syntax: swapf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f<3:0>) ? dest<7:4>, (f<7:4>) ? dest<3:0> status affected: none encoding: 0011 10da ffff ffff description: the upper and lower nibbles of register ?f? are exchanged. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed in register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: swapf reg, 1, 0 before instruction reg = 53h after instruction reg = 35h
? 2012 microchip technology inc. ds30575a-page 613 pic18f97j94 family tblrd table read syntax: tblrd ( *; *+; *-; +*) operands: none operation: if tblrd *, (prog mem (tblptr)) ? tablat; tblptr ? no change if tblrd *+, (prog mem (tblptr)) ? tablat; (tblptr) + 1 ? tblptr if tblrd *-, (prog mem (tblptr)) ? tablat; (tblptr) ? 1 ? tblptr if tblrd +*, (tblptr) + 1 ? tblptr; (prog mem (tblptr)) ? tablat status affected: none encoding: 0000 0000 0000 10nn nn=0 * =1 *+ =2 *- =3 +* description: this instruction is used to read the contents of program memory (p.m.). to address the program memory, a pointer called table pointer (tblptr) is used. the tblptr (a 21-bit pointer) points to each byte in the program memory. tblptr has a 2-mbyte address range. tblptr<0> = 0 :least significant byte of program memory word tblptr<0> = 1 :most significant byte of program memory word the tblrd instruction can modify the value of tblptr as follows: ? no change ? post-increment ? post-decrement ? pre-increment words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation no operation no operation (read program memory) no operation no operation (write tablat) tblrd table read (continued) example 1: tblrd *+ ; before instruction tablat = 55h tblptr = 00a356h memory(00a356h) = 34h after instruction tablat = 34h tblptr = 00a357h example 2: tblrd +* ; before instruction tablat = aah tblptr = 01a357h memory(01a357h) = 12h memory(01a358h) = 34h after instruction tablat = 34h tblptr = 01a358h
pic18f97j94 family ds30575a-page 614 ? 2012 microchip technology inc. tblwt table write syntax: tblwt ( *; *+; *-; +*) operands: none operation: if tblwt*, (tablat) ? holding register; tblptr ? no change if tblwt*+, (tablat) ? holding register; (tblptr) + 1 ? tblptr if tblwt*-, (tablat) ? holding register; (tblptr) ? 1 ? tblptr if tblwt+*, (tblptr) + 1 ? tblptr; (tablat) ? holding register status affected: none encoding: 0000 0000 0000 11nn nn=0 * =1 *+ =2 *- =3 +* description: this instruction uses the 3 lsbs of tblptr to determine which of the 8 holding registers the tablat is written to. the holding registers are used to program the contents of program memory (p.m.). (refer to section 6.0 ?memory organization? for additional details on programming flash memory.) the tblptr (a 21-bit pointer) points to each byte in the program memory. tblptr has a 2-mbyte address range. the lsb of the tblptr selects which byte of the program memory location to access. tblptr[0] = 0 :least significant byte of program memory word tblptr[0] = 1 :most significant byte of program memory word the tblwt instruction can modify the value of tblptr as follows: ? no change ? post-increment ? post-decrement ? pre-increment words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation no operation no operation (read tablat) no operation no operation (write to holding register) tblwt table write (continued) example 1: tblwt *+; before instruction tablat = 55h tblptr = 00a356h holding register (00a356h) = ffh after instructions (table write completion) tablat = 55h tblptr = 00a357h holding register (00a356h) = 55h example 2: tblwt +*; before instruction tablat = 34h tblptr = 01389ah holding register (01389ah) = ffh holding register (01389bh) = ffh after instruction (table write completion) tablat = 34h tblptr = 01389bh holding register (01389ah) = ffh holding register (01389bh) = 34h
? 2012 microchip technology inc. ds30575a-page 615 pic18f97j94 family tstfsz test f, skip if 0 syntax: tstfsz f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: skip if f = 0 status affected: none encoding: 0110 011a ffff ffff description: if ?f? = 0 , the next instruction fetched during the current instruction execution is discarded and a nop is executed, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here tstfsz cnt, 1 nzero : zero : before instruction pc = address (here) after instruction if cnt = 00h, pc = address (zero) if cnt ? 00h, pc = address (nzero) xorlw exclusive or literal with w syntax: xorlw k operands: 0 ?? k ?? 255 operation: (w) .xor. k ?? w status affected: n, z encoding: 0000 1010 kkkk kkkk description: the contents of w are xored with the 8-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: xorlw 0afh before instruction w=b5h after instruction w=1ah
pic18f97j94 family ds30575a-page 616 ? 2012 microchip technology inc. xorwf exclusive or w with f syntax: xorwf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (w) .xor. (f) ?? dest status affected: n, z encoding: 0001 10da ffff ffff description: exclusive or the contents of w with register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in the register ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: xorwf reg, 1, 0 before instruction reg = afh w=b5h after instruction reg = 1ah w=b5h
? 2012 microchip technology inc. ds30575a-page 617 pic18f97j94 family 29.2 extended instruction set in addition to the standard 75 instructions of the pic18 instruction set, the pic18f97j94 family of devices also provides an optional extension to the core cpu func- tionality. the added features include eight additional instructions that augment indirect and indexed addressing operations and the implementation of indexed literal offset addressing for many of the standard pic18 instructions. the additional features of the extended instruction set are enabled by default on unprogrammed devices. users must properly set or clear the xinst configura- tion bit during programming to enable or disable these features. the instructions in the extended set can all be classified as literal operations, which either manipulate the file select registers, or use them for indexed addressing. two of the instructions, addfsr and subfsr , each have an additional special instantiation for using fsr2. these versions ( addulnk and subulnk ) allow for automatic return after execution. the extended instructions are specifically implemented to optimize re-entrant program code (that is, code that is recursive or that uses a software stack) written in high-level languages, particularly c. among other things, they allow users working in high-level languages to perform certain operations on data structures more efficiently. these include: ? dynamic allocation and deallocation of software stack space when entering and leaving subroutines ? function pointer invocation ? software stack pointer manipulation ? manipulation of variables located in a software stack a summary of the instructions in the extended instruc- tion set is provided in tab l e 2 9- 3 . detailed descriptions are provided in section 29.2.2 ?extended instruction set? . the opcode field descriptions in tab l e 2 9- 1 (page 576 ) apply to both the standard and extended pic18 instruction sets. 29.2.1 extended instruction syntax most of the extended instructions use indexed argu- ments, using one of the file select registers and some offset to specify a source or destination register. when an argument for an instruction serves as part of indexed addressing, it is enclosed in square brackets (?[ ]?). this is done to indicate that the argument is used as an index or offset. the mpasm? assembler will flag an error if it determines that an index or offset value is not bracketed. when the extended instruction set is enabled, brackets are also used to indicate index arguments in byte-oriented and bit-oriented instructions. this is in addition to other changes in their syntax. for more details, see section 29.2.3.1 ?extended instruction syntax with standard pic18 commands? . table 29-3: extensions to the pic18 instruction set note: the instruction set extension and the indexed literal offset addressing mode were designed for optimizing applications written in c; the user may likely never use these instructions directly in assembler. the syntax for these commands is provided as a reference for users who may be reviewing code that has been generated by a compiler. note: in the past, square brackets have been used to denote optional arguments in the pic18 and earlier instruction sets. in this text and going forward, optional arguments are denoted by braces (?{ }?). mnemonic, operands description cycles 16-bit instruction word status affected msb lsb addfsr addulnk callw movsf movss pushl subfsr subulnk f, k k z s , f d z s , z d k f, k k add literal to fsr add literal to fsr2 and return call subroutine using wreg move z s (source) to 1st word f d (destination) 2nd word move z s (source) to 1st word z d (destination) 2nd word store literal at fsr2, decrement fsr2 subtract literal from fsr subtract literal from fsr2 and return 1 2 2 2 2 1 1 2 1110 1110 0000 1110 1111 1110 1111 1110 1110 1110 1000 1000 0000 1011 ffff 1011 xxxx 1010 1001 1001 ffkk 11kk 0001 0zzz ffff 1zzz xzzz kkkk ffkk 11kk kkkk kkkk 0100 zzzz ffff zzzz zzzz kkkk kkkk kkkk none none none none none none none none
pic18f97j94 family ds30575a-page 618 ? 2012 microchip technology inc. 29.2.2 extended instruction set addfsr add literal to fsr syntax: addfsr f, k operands: 0 ? k ? 63 f ? [ 0, 1, 2 ] operation: fsr(f) + k ? fsr(f) status affected: none encoding: 1110 1000 ffkk kkkk description: the 6-bit literal ?k? is added to the contents of the fsr specified by ?f?. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to fsr example: addfsr 2, 23h before instruction fsr2 = 03ffh after instruction fsr2 = 0422h addulnk add literal to fsr2 and return syntax: addulnk k operands: 0 ? k ? 63 operation: fsr2 + k ? fsr2, (tos) ?? pc status affected: none encoding: 1110 1000 11kk kkkk description: the 6-bit literal ?k? is added to the contents of fsr2. a return is then executed by loading the pc with the tos. the instruction takes two cycles to execute; a nop is performed during the second cycle. this may be thought of as a special case of the addfsr instruction, where f = 3 (binary ? 11 ?); it operates only on fsr2. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to fsr no operation no operation no operation no operation example: addulnk 23h before instruction fsr2 = 03ffh pc = 0100h after instruction fsr2 = 0422h pc = (tos) note: all pic18 instructions may take an optional label argument preceding the instruction mnemonic for use in symbolic addressing. if a label is used, the instruction format then becomes: {label} instruction argument(s).
? 2012 microchip technology inc. ds30575a-page 619 pic18f97j94 family callw subroutine call using wreg syntax: callw operands: none operation: (pc + 2) ? tos, (w) ? pcl, (pclath) ? pch, (pclatu) ? pcu status affected: none encoding: 0000 0000 0001 0100 description first, the return address (pc + 2) is pushed onto the return stack. next, the contents of w are written to pcl; the existing value is discarded. then, the contents of pclath and pclatu are latched into pch and pcu, respectively. the second cycle is executed as a nop instruction while the new next instruction is fetched. unlike call , there is no option to update w, status or bsr. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read wreg push pc to stack no operation no operation no operation no operation no operation example: here callw before instruction pc = address (here) pclath = 10h pclatu = 00h w = 06h after instruction pc = 001006h tos = address (here + 2) pclath = 10h pclatu = 00h w = 06h movsf move indexed to f syntax: movsf [z s ], f d operands: 0 ? z s ? 127 0 ? f d ? 4095 operation: ((fsr2) + z s ) ? f d status affected: none encoding: 1st word (source) 2nd word (destin.) 1110 1111 1011 ffff 0zzz ffff zzzz s ffff d description: the contents of the source register are moved to destination register ?f d ?. the actual address of the source register is determined by adding the 7-bit literal offset ?z s ?, in the first word, to the value of fsr2. the address of the destination register is specified by the 12-bit literal ?f d ? in the second word. both addresses can be anywhere in the 4096-byte data space (000h to fffh). the movsf instruction cannot use the pcl, tosu, tosh or tosl as the destination register. if the resultant source address points to an indirect addressing register, the value returned will be 00h. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode determine source addr determine source addr read source reg decode no operation no dummy read no operation write register ?f? (dest) example: movsf [05h], reg2 before instruction fsr2 = 80h contents of 85h = 33h reg2 = 11h after instruction fsr2 = 80h contents of 85h = 33h reg2 = 33h
pic18f97j94 family ds30575a-page 620 ? 2012 microchip technology inc. movss move indexed to indexed syntax: movss [z s ], [z d ] operands: 0 ? z s ? 127 0 ? z d ? 127 operation: ((fsr2) + z s ) ? ((fsr2) + z d ) status affected: none encoding: 1st word (source) 2nd word (dest.) 1110 1111 1011 xxxx 1zzz xzzz zzzz s zzzz d description the contents of the source register are moved to the destination register. the addresses of the source and destination registers are determined by adding the 7-bit literal offsets, ?z s ? or ?z d ?, respectively, to the value of fsr2. both registers can be located anywhere in the 4096-byte data memory space (000h to fffh). the movss instruction cannot use the pcl, tosu, tosh or tosl as the destination register. if the resultant source address points to an indirect addressing register, the value returned will be 00h. if the resultant destination address points to an indirect addressing register, the instruction will execute as a nop . words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode determine source addr determine source addr read source reg decode determine dest addr determine dest addr write to dest reg example: movss [05h], [06h] before instruction fsr2 = 80h contents of 85h = 33h contents of 86h = 11h after instruction fsr2 = 80h contents of 85h = 33h contents of 86h = 33h pushl store literal at fsr2, decrement fsr2 syntax: pushl k operands: 0 ??? k ? 255 operation: k ? (fsr2), fsr2 ? 1 ? fsr2 status affected: none encoding: 1111 1010 kkkk kkkk description: the 8-bit literal ?k? is written to the data memory address specified by fsr2. fsr2 is decremented by 1 after the operation. this instruction allows users to push values onto a software stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write to destination example: pushl 08h before instruction fsr2h:fsr2l = 01ech memory (01ech) = 00h after instruction fsr2h:fsr2l = 01ebh memory (01ech) = 08h
? 2012 microchip technology inc. ds30575a-page 621 pic18f97j94 family subfsr subtract literal from fsr syntax: subfsr f, k operands: 0 ? k ? 63 f ? [ 0, 1, 2 ] operation: fsrf ? k ? fsrf status affected: none encoding: 1110 1001 ffkk kkkk description: the 6-bit literal ?k? is subtracted from the contents of the fsr specified by ?f?. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: subfsr 2, 23h before instruction fsr2 = 03ffh after instruction fsr2 = 03dch subulnk subtract literal from fsr2 and return syntax: subulnk k operands: 0 ? k ? 63 operation: fsr2 ? k ? fsr2, (tos) ?? pc status affected: none encoding: 1110 1001 11kk kkkk description: the 6-bit literal ?k? is subtracted from the contents of the fsr2. a return is then executed by loading the pc with the tos. the instruction takes two cycles to execute; a nop is performed during the second cycle. this may be thought of as a special case of the subfsr instruction, where f = 3 (binary ? 11 ?); it operates only on fsr2. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination no operation no operation no operation no operation example: subulnk 23h before instruction fsr2 = 03ffh pc = 0100h after instruction fsr2 = 03dch pc = (tos)
pic18f97j94 family ds30575a-page 622 ? 2012 microchip technology inc. 29.2.3 byte-oriented and bit-oriented instructions in indexed literal offset mode in addition to eight new commands in the extended set, enabling the extended instruction set also enables indexed literal offset addressing ( section 6.6.1 ?indexed addressing with literal offset? ). this has a significant impact on the way that many commands of the standard pic18 instruction set are interpreted. when the extended set is disabled, addresses embed- ded in opcodes are treated as literal memory locations: either as a location in the access bank (a = 0 ) or in a gpr bank designated by the bsr (a = 1 ). when the extended instruction set is enabled and a = 0 , however, a file register argument of 5fh or less is interpreted as an offset from the pointer value in fsr2 and not as a literal address. for practical purposes, this means that all instructions that use the access ram bit as an argument ? that is, all byte-oriented and bit-oriented instructions, or almost half of the core pic18 instruc- tions ? may behave differently when the extended instruction set is enabled. when the content of fsr2 is 00h, the boundaries of the access ram are essentially remapped to their original values. this may be useful in creating backward compatible code. if this technique is used, it may be necessary to save the value of fsr2 and restore it when moving back and forth between c and assembly routines in order to preserve the stack pointer. users must also keep in mind the syntax requirements of the extended instruction set (see section 29.2.3.1 ?extended instruction syntax with standard pic18 commands? ). although the indexed literal offset mode can be very useful for dynamic stack and pointer manipulation, it can also be very annoying if a simple arithmetic opera- tion is carried out on the wrong register. users who are accustomed to the pic18 programming must keep in mind, that when the extended instruction set is enabled, register addresses of 5fh or less are used for indexed literal offset addressing. representative examples of typical byte-oriented and bit-oriented instructions in the indexed literal offset mode are provided on the following page to show how execution is affected. the operand conditions shown in the examples are applicable to all instructions of these types. 29.2.3.1 extended instruction syntax with standard pic18 commands when the extended instruction set is enabled, the file register argument ?f? in the standard byte-oriented and bit-oriented commands is replaced with the literal offset value ?k?. as already noted, this occurs only when ?f? is less than or equal to 5fh. when an offset value is used, it must be indicated by square brackets (?[ ]?). as with the extended instructions, the use of brackets indicates to the compiler that the value is to be interpreted as an index or an offset. omitting the brackets, or using a value greater than 5fh within the brackets, will generate an error in the mpasm? assembler. if the index argument is properly bracketed for indexed literal offset addressing, the access ram argument is never specified; it will automatically be assumed to be ? 0 ?. this is in contrast to standard operation (extended instruction set disabled), when ?a? is set on the basis of the target address. declaring the access ram bit in this mode will also generate an error in the mpasm assembler. the destination argument, ?d?, functions as before. in the latest versions of the mpasm assembler, language support for the extended instruction set must be explicitly invoked. this is done with either the command-line option, /y , or the pe directive in the source listing. 29.2.4 considerations when enabling the extended instruction set it is important to note that the extensions to the instruc- tion set may not be beneficial to all users. in particular, users who are not writing code that uses a software stack may not benefit from using the extensions to the instruction set. additionally, the indexed literal offset addressing mode may create issues with legacy applications written to the pic18 assembler. this is because instructions in the legacy code may attempt to address registers in the access bank below 5fh. since these addresses are interpreted as literal offsets to fsr2 when the instruction set extension is enabled, the application may read or write to the wrong data addresses. when porting an application to the pic18f97j94 family, it is very important to consider the type of code. a large, re-entrant application that is written in c and would benefit from efficient compilation will do well when using the instruction set extensions. legacy applications that heavily use the access bank will most likely not benefit from using the extended instruction set. note: enabling the pic18 instruction set exten- sion may cause legacy applications to behave erratically or fail entirely.
? 2012 microchip technology inc. ds30575a-page 623 pic18f97j94 family addwf add w to indexed (indexed literal offset mode) syntax: addwf [k] {,d} operands: 0 ? k ? 95 d ? [0,1] operation: (w) + ((fsr2) + k) ? dest status affected: n, ov, c, dc, z encoding: 0010 01d0 kkkk kkkk description: the contents of w are added to the contents of the register indicated by fsr2, offset by the value ?k?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f?. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write to destination example: addwf [ofst] ,0 before instruction w = 17h ofst = 2ch fsr2 = 0a00h contents of 0a2ch = 20h after instruction w = 37h contents of 0a2ch = 20h bsf bit set indexed (indexed literal offset mode) syntax: bsf [k], b operands: 0 ? f ? 95 0 ? b ? 7 operation: 1 ? ((fsr2) + k) status affected: none encoding: 1000 bbb0 kkkk kkkk description: bit ?b? of the register indicated by fsr2, offset by the value ?k?, is set. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: bsf [flag_ofst], 7 before instruction flag_ofst = 0ah fsr2 = 0a00h contents of 0a0ah = 55h after instruction contents of 0a0ah = d5h setf set indexed (indexed literal offset mode) syntax: setf [k] operands: 0 ? k ? 95 operation: ffh ? ((fsr2) + k) status affected: none encoding: 0110 1000 kkkk kkkk description: the contents of the register indicated by fsr2, offset by ?k?, are set to ffh. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write register example: setf [ofst] before instruction ofst = 2ch fsr2 = 0a00h contents of 0a2ch = 00h after instruction contents of 0a2ch = ffh
pic18f97j94 family ds30575a-page 624 ? 2012 microchip technology inc. 29.2.5 special considerations with microchip mplab ? ide tools the latest versions of microchip?s software tools have been designed to fully support the extended instruction set for the pic18f97j94 family. this includes the mplab c18 c compiler, mpasm assembly language and mplab integrated development environment (ide). when selecting a target device for software development, mplab ide will automatically set default configuration bits for that device. the default setting for the xinst configuration bit is ? 1 ?, enabling the extended instruction set and indexed literal offset addressing. for proper execution of applications developed to take advantage of the extended instruction set, xinst must be set during programming. to develop software for the extended instruction set, the user must enable support for the instructions and the indexed addressing mode in their language tool(s). depending on the environment being used, this may be done in several ways: ? a menu option or dialog box within the environment that allows the user to configure the language tool and its settings for the project ? a command-line option ? a directive in the source code these options vary between different compilers, assemblers and development environments. users are encouraged to review the documentation accompany- ing their development systems for the appropriate information.
? 2012 microchip technology inc. ds30575a-page 625 pic18f97j94 family 30.0 development support the pic ? microcontrollers and dspic ? digital signal controllers are supported with a full range of software and hardware development tools: ? integrated development environment - mplab ? ide software ? compilers/assemblers/linkers - mplab c compiler for various device families - hi-tech c ? for various device families - mpasm tm assembler -mplink tm object linker/ mplib tm object librarian - mplab assembler/linker/librarian for various device families ? simulators - mplab sim software simulator ?emulators - mplab real ice? in-circuit emulator ? in-circuit debuggers - mplab icd 3 - pickit? 3 debug express ? device programmers - pickit? 2 programmer - mplab pm3 device programmer ? low-cost demonstration/development boards, evaluation kits, and starter kits 30.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16/32-bit microcontroller market. the mplab ide is a windows ? operating system-based application that contains: ? a single graphical interface to all debugging tools - simulator - programmer (sold separately) - in-circuit emulator (sold separately) - in-circuit debugger (sold separately) ? a full-featured editor with color-coded context ? a multiple project manager ? customizable data windows with direct edit of contents ? high-level source code debugging ? mouse over variable inspection ? drag and drop variables from source to watch windows ? extensive on-line help ? integration of select third party tools, such as iar c compilers the mplab ide allows you to: ? edit your source files (either c or assembly) ? one-touch compile or assemble, and download to emulator and simulator tools (automatically updates all project information) ? debug using: - source files (c or assembly) - mixed c and assembly - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost-effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increased flexibility and power.
pic18f97j94 family ds30575a-page 626 ? 2012 microchip technology inc. 30.2 mplab c compilers for various device families the mplab c compiler code development systems are complete ansi c compilers for microchip?s pic18, pic24 and pic32 families of microcontrollers and the dspic30 and dspic33 families of digital signal control- lers. these compilers provide powerful integration capabilities, superior code optimization and ease of use. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 30.3 hi-tech c for various device families the hi-tech c compiler code development systems are complete ansi c compilers for microchip?s pic family of microcontrollers and the dspic family of digital signal controllers. these compilers provide powerful integration capabilities, omniscient code generation and ease of use. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. the compilers include a macro assembler, linker, pre- processor, and one-step driver, and can run on multiple platforms. 30.4 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for pic10/12/16/18 mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol reference, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include: ? integration into mplab ide projects ? user-defined macros to streamline assembly code ? conditional assembly for multi-purpose source files ? directives that allow complete control over the assembly process 30.5 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c18 c compiler. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include: ? efficient linking of single libraries instead of many smaller files ? enhanced code maintainability by grouping related modules together ? flexible creation of libraries with easy module listing, replacement, deletion and extraction 30.6 mplab assembler, linker and librarian for various device families mplab assembler produces relocatable machine code from symbolic assembly language for pic24, pic32 and dspic devices. mplab c compiler uses the assembler to produce its object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include: ? support for the entire device instruction set ? support for fixed-point and floating-point data ? command line interface ? rich directive set ? flexible macro language ? mplab ide compatibility
? 2012 microchip technology inc. ds30575a-page 627 pic18f97j94 family 30.7 mplab sim software simulator the mplab sim software simulator allows code development in a pc-hosted environment by simulat- ing the pic mcus and dspic ? dscs on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a comprehensive stimulus controller. registers can be logged to files for further run-time analysis. the trace buffer and logic analyzer display extend the power of the simulator to record and track program execution, actions on i/o, most peripherals and internal registers. the mplab sim software simulator fully supports symbolic debugging using the mplab c compilers, and the mpasm and mplab assemblers. the soft- ware simulator offers the flexibility to develop and debug code outside of the hardware laboratory envi- ronment, making it an excellent, economical software development tool. 30.8 mplab real ice in-circuit emulator system mplab real ice in-circuit emulator system is microchip?s next generation high-speed emulator for microchip flash dsc and mcu devices. it debugs and programs pic ? flash mcus and dspic ? flash dscs with the easy-to-use, powerful graphical user interface of the mplab integrated development environment (ide), included with each kit. the emulator is connected to the design engineer?s pc using a high-speed usb 2.0 interface and is connected to the target with either a connector compatible with in- circuit debugger systems (rj11) or with the new high- speed, noise tolerant, low-voltage differential signal (lvds) interconnection (cat5). the emulator is field upgradable through future firmware downloads in mplab ide. in upcoming releases of mplab ide, new devices will be supported, and new features will be added. mplab real ice offers significant advantages over competitive emulators including low-cost, full-speed emulation, run-time variable watches, trace analysis, complex breakpoints, a ruggedized probe interface and long (up to three meters) interconnection cables. 30.9 mplab icd 3 in-circuit debugger system mplab icd 3 in-circuit debugger system is micro- chip's most cost effective high-speed hardware debugger/programmer for microchip flash digital sig- nal controller (dsc) and microcontroller (mcu) devices. it debugs and programs pic ? flash microcon- trollers and dspic ? dscs with the powerful, yet easy- to-use graphical user interface of mplab integrated development environment (ide). the mplab icd 3 in-circuit debugger probe is con- nected to the design engineer's pc using a high-speed usb 2.0 interface and is connected to the target with a connector compatible with the mplab icd 2 or mplab real ice systems (rj-11). mplab icd 3 supports all mplab icd 2 headers. 30.10 pickit 3 in-circuit debugger/ programmer and pickit 3 debug express the mplab pickit 3 allows debugging and program- ming of pic ? and dspic ? flash microcontrollers at a most affordable price point using the powerful graphical user interface of the mplab integrated development environment (ide). the mplab pickit 3 is connected to the design engineer's pc using a full speed usb interface and can be connected to the target via an microchip debug (rj-11) connector (compatible with mplab icd 3 and mplab real ice). the connector uses two device i/o pins and the reset line to imple- ment in-circuit debugging and in-circuit serial pro- gramming?. the pickit 3 debug express include the pickit 3, demo board and microcontroller, hookup cables and cdrom with user?s guide, lessons, tutorial, compiler and mplab ide software.
pic18f97j94 family ds30575a-page 628 ? 2012 microchip technology inc. 30.11 pickit 2 development programmer/debugger and pickit 2 debug express the pickit? 2 development programmer/debugger is a low-cost development tool with an easy to use inter- face for programming and debugging microchip?s flash families of microcontrollers. the full featured windows ? programming interface supports baseline (pic10f, pic12f5xx, pic16f5xx), midrange (pic12f6xx, pic16f), pic18f, pic24, dspic30, dspic33, and pic32 families of 8-bit, 16-bit, and 32-bit microcontrollers, and many microchip serial eeprom products. with microchip?s powerful mplab integrated development environment (ide) the pickit? 2 enables in-circuit debugging on most pic ? microcon- trollers. in-circuit-debugging runs, halts and single steps the program while the pic microcontroller is embedded in the application. when halted at a break- point, the file registers can be examined and modified. the pickit 2 debug express include the pickit 2, demo board and microcontroller, hookup cables and cdrom with user?s guide, lessons, tutorial, compiler and mplab ide software. 30.12 mplab pm3 device programmer the mplab pm3 device programmer is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modu- lar, detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand-alone mode, the mplab pm3 device programmer can read, verify and program pic devices without a pc connection. it can also set code protection in this mode. the mplab pm3 connects to the host pc via an rs-232 or usb cable. the mplab pm3 has high-speed communications and optimized algorithms for quick programming of large memory devices and incorporates an mmc card for file storage and data applications. 30.13 demonstration/development boards, evaluation kits, and starter kits a wide variety of demonstration, development and evaluation boards for various pic mcus and dspic dscs allows quick application development on fully func- tional systems. most boards include prototyping areas for adding custom circuitry and provide application firmware and source code for examination and modification. the boards support a variety of features, including leds, temperature sensors, switches, speakers, rs-232 interfaces, lcd displays, potentiometers and additional eeprom memory. the demonstration and development boards can be used in teaching environments, for prototyping custom circuits and for learning about various microcontroller applications. in addition to the picdem? and dspicdem? demon- stration/development board series of circuits, microchip has a line of evaluation kits and demonstration software for analog filter design, k ee l oq ? security ics, can, irda ? , powersmart battery management, seeval ? evaluation system, sigma-delta adc, flow rate sensing, plus many more. also available are starter kits that contain everything needed to experience the specified device. this usually includes a single application and debug capability, all on one board. check the microchip web page ( www.microchip.com ) for the complete list of demonstration, development and evaluation kits.
? 2012 microchip technology inc. ds30575a-page 629 pic18f97j94 family 31.0 electrical characteristics absolute maximum ratings ( ? ) ambient temperature under bias................................................................................................. ............-40c to +100c storage temperature ............................................................................................................ .................. -65c to +150c voltage on mclr with respect to v ss .......................................................................................................... -0.3v to 5.5v voltage on any digital only i/o pin with respect to v ss (except v dd )........................................................... -0.3v to 5.5v voltage on any combined digital and analog pin with respect to v ss (except v dd and mclr )...... -0.3v to (v dd + 0.3v) voltage on v bat with respect to v ss ......................................................................................................... -0.3v to 3.66v voltage on v usb 3 v 3 with respect to v ss ........................................................................................ (v dd ? 0.3v) to +4.0v voltage on v dd with respect to v ss .......................................................................................................... -0.3v to 3.66v voltage on d+ or d- with respect to v ss ? 0w source impedance ( note 2 ) ............................ -0.5v to (v usb 3 v 3 + 0.5v) source impedance ? 28w, v usb 3 v 3 ? 3.0v) .............................................................................................. -1.0v to +4.6v total power dissipation (note 1 ) ............................................................................................................................... ...1w maximum current out of v ss pin ........................................................................................................................... 300 ma maximum current into v dd pin ........................................................................................................................... ...250 ma input clamp current, i ik (v i < 0 or v i > v dd ) .......................................................................................................... 20 ma output clamp current, i ok (v o < 0 or v o > v dd ) .................................................................................................. 20 ma maximum output current sunk by any i/o pins.................................................................................... ....................25 ma maximum output current sourced by any i/o pins................................................................................. ..................25 ma maximum current sunk by ? all ports combined.......................................................................................................200 ma maximum current sourced by all ports combined.................................................................................. ................200 ma note 1: power dissipation is calculated as follows: pdis = v dd x {i dd ? ? i oh } + ? {(v dd ? v oh ) x i oh } + ? (v ol x i ol ) 2: the original ? usb 2.0 specification ? indicated that usb devices should withstand 24-hour short circuits of d+ or d- to v bus voltages. this requirement was later removed in an engineering change notice (ecn) sup- plement to the usb specifications, which supersedes the original specifications. pic18f97j94 family devices will typically be able to survive this short circuit test, but it is recommended to adhere to the absolute maximum specified here to avoid damaging the device. ? notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operat ion of the device at those or any other conditions above those indicated in the operation listings of this specific ation is not implied. exposure to maximum rating conditions for extended periods may affect device reliability.
pic18f97j94 family ds30575a-page 630 ? 2012 microchip technology inc. figure 31-1: voltage-frequency graph, regulator disabled (industrial) ( 1 , 2 ) frequency voltage (v dd ) 4v 2v 64 mhz 3.75v 3.25v 2.5v 3.6v 4 mhz 3v note 1: when the usb module is enabled, v usb 3 v 3 and v dd should be connected together and provided 3.0v-3.6v. when the usb module is not enabled, v usb 3 v 3 and v dd should still be connected together. 2: v cap (nominal on-chip regulator output voltage) = 1.8v. pic18f97j94 family
? 2012 microchip technology inc. ds30575a-page 631 pic18f97j94 family 31.1 dc characteristics: supply voltage pic18f97j94 (industrial) pic18f97j94 (industrial) standard operating conditions: 2v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c param no. symbol characteristic min typ max units conditions d001 v dd supply voltage 2.0 ? 3.6 v d001c av dd analog supply voltage v dd ? 0.3 ? v dd + 0.3 v d001d av ss analog ground potential v ss ? 0.3 ? v ss + 0.3 v d001e v usb 3 v 3 usb supply voltage 3 3.3 3.6 v usb module enabled ( 3 ) d002 v dr ram data retention voltage ( 1 ) 1.2 ? ? v d003 v por v dd /v bat start voltage to ensure internal power-on reset signal ? ? 0.7 v see section 5.2 ?power-on reset (por)? for details d004 s vdd v dd /v bat rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms see section 5.2 ?power-on reset (por)? for details d005 b vdd brown-out reset voltage borv = 1 ( 2 ) borv = 0 1.8 2.0 1.88 2.05 1.95 2.20 v v d006 v vddbor 1.4v 2.0 v d007 v vbatbor 1.4v 1.95 v d008 v dsbor 1.8 note 1: this is the limit to which v dd can be lowered in sleep mode, or during a device reset, without losing ram data. 2: the device will operate normally until brown-out reset occurs, even though v dd may be below v ddmin . 3: v usb 3 v 3 should be connected to v dd .
pic18f97j94 family ds30575a-page 632 ? 2012 microchip technology inc. table 31-1: dc characteristics: power-down and supply current pic18f97j94 family (industrial) 31.2 dc characteristics: power-down and supply current pic18f97j94 (industrial) pic18f97j94 family (industrial) standard operating conditions: 2v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial param no. typ ( 1 ) max units conditions dc60 3.7 7.0 a -40c 2.0v sleep ( 2 ) 3.7 7.0 a +25c 5.0 9.0 a +60c 9.0 18 a +85c 3.7 8.0 a -40c 3.3v 3.7 8.0 a +25c 5.0 11.0 a +60c 10 20 a +85c dc61 0.07 0.55 a -40c 2.0v retention sleep or retention deep sleep ( 3 ) 0.09 0.55 a +25c 2.0 3.2 a +60c 7.0 8.5 a +85c 0.10 0.65 a -40c 3.3v 0.15 0.65 a +25c 2.0 3.5 a +60c 7.2 9.0 a +85c dc70 0.06 0.5 a -40c 2.0v deep sleep 0.08 0.5 a +25c 0.21 0.8 a +60c 0.41 1.5 a +85c 0.09 0.6 a -40c 3.3v 0.11 0.6 a +25c 0.42 1.2 a +60c 0.8 4.8 a +85c 0.4 3.0 a -40c to +85c 0 rtcc with v bat mode (lprc or sosc) ( 4 ) note 1: data in the typical column is at 3.3v, 25c; typical parameters are for design guidance only and are not tested. 2: retention regulator is disabled; sreten (rcon4<4>= 0) , reten (config7l<0>= 1) . 3: retention regulator is enabled; sreten (rcon4<4> = 1) , reten (config7l<0> = 0) . 4: v bat pin is connected to the battery and rtcc is running with v dd = 0 . param no. device typ max units conditions supply current (i dd ) all devices 22 55 a -40c to +85c v dd = 2.0v f osc = 31 khz, rc_run 23 56 a -40c to +85c v dd = 3.3v 21 54 a -40c to +85c v dd = 2.0v f osc = 31 khz, rc_idle 22 55 a -40c to +85c v dd = 3.3v
? 2012 microchip technology inc. ds30575a-page 633 pic18f97j94 family table 31-2: dc characteristics: power-down and supply current pic18f97j94 family (industrial) table 31-3: dc characteristics: power-down and supply current pic18f97j94 family (industrial) param no. device typ max units conditions supply current (i dd ) all devices 22 55 a -40c to +85c v dd = 2.0v f osc = 32 khz, sec_run 23 56 a -40c to +85c v dd = 3.3v 21 54 a -40c to +85c v dd =2.0v f osc = 32 khz, sec_idle 22 55 a -40c to +85c v dd = 3.3v param no. device typ max units conditions supply current (i dd ) all devices 325 430 a -40c to +85c v dd = 2.0v f osc = 1 mhz, rc_run 325 430 a -40c to +85c v dd = 3.3v 540 700 a -40c to +85c v dd = 2.0v f osc = 4 mhz, rc_run 540 700 a -40c to +85c v dd = 3.3v 820 1000 a -40c to +85c v dd = 2.0v f osc = 8 mhz, rc_run 825 1000 a -40c to +85c v dd = 3.3v 275 370 a -40c to +85c v dd = 2.0v f osc = 1 mhz, rc_idle 275 370 a -40c to +85c v dd = 3.3v 345 440 a -40c to +85c v dd = 2.0v f osc = 4 mhz, rc_idle 345 440 a -40c to +85c v dd = 3.3v 435 620 a -40c to +85c v dd = 2.0v f osc = 8 mhz, rc_idle 435 620 a -40c to +85c v dd = 3.3v
pic18f97j94 family ds30575a-page 634 ? 2012 microchip technology inc. table 31-4: dc characteristics: power-down and supply current pic18f97j94 family (industrial) param no. device typ max units conditions supply current (i dd ) all devices 100 150 a -40c to +85c v dd = 2.0v f osc = 1 mhz, pri_run mode, ec oscillator 105 155 a -40c to +85c v dd = 3.3v 330 390 a -40c to +85c v dd = 2.0v f osc = 4 mhz, pri_run mode, ec oscillator 340 405 a -40c to +85c v dd = 3.3v 5.0 5.5 ma -40c to +85c v dd = 2.0v f osc = 64 mhz, pri_run mode, ec oscillator 5.0 5.5 ma -40c to +85c v dd = 3.3v 5.7 6.5 ma -40c to +85c v dd = 2.0v f osc = 64 mhz, pri_run mode, 8 mhz ec oscillator with 96 mhz or 8x pll 5.7 7.0 ma -40c to +85c v dd = 3.3v 52 90 a -40c to +85c v dd = 2.0v f osc = 1 mhz, pri_idle mode, ec oscillator 66 95 a -40c to +85c v dd = 3.3v 135 185 a -40c to +85c v dd = 2.0v f osc = 4 mhz, pri_idle mode, ec oscillator 145 195 a -40c to +85c v dd = 3.3v 1.8 2.6 ma -40c to +85c v dd = 2.0v f osc = 64 mhz, pri_idle mode, ec oscillator 2.0 2.8 ma -40c to +85c v dd = 3.3v 2.3 2.9 ma -40c to +85c v dd = 2.0v f osc = 64 mhz, pri_idle mode, 8 mhz ec oscillator with 96 mhz or 8x pll 2.4 3.0 ma -40c to +85c v dd = 3.3v
? 2012 microchip technology inc. ds30575a-page 635 pic18f97j94 family table 31-5: dc characteristics: power-down and supply current pic18f97j94 family (industrial) table 31-6: d c characteristics: power-down and supply current pic18f97j94 family (industrial) param no. device typ ( 1 ) max units conditions module differential currents ( i wdt , i bor , i hlvd , i dsbor , i dswdt , i oscb , i adrc , i lcd , i usb ) d020 ( i wdt ) watchdog timer 0.4 1 a -40c to +85c v dd = 2.0v 0.4 1 a -40c to +85c v dd = 3.3v d021 ( i bor ) brown-out reset 4 8 a -40c to +85c v dd = 2.0v high-power bor 5 9 a -40c to +85c v dd = 3.3v d022 ( i hlvd ) high/low-voltage detect 4 8 a -40c to +85c v dd = 2.0v 5 9 a -40c to +85c v dd = 3.3v d023 ( i dsbor ) deep sleep bor 135 480 na -40c to +85c v dd = 2.0v to 3.3v deep sleep bor ( 2 ) d024 ( i dswdt ) deep sleep watchdog timer 290 480 na -40c to +85c v dd = 2.0v to 3.3v deep sleep wdt ( 2 ) d025 ( i oscb ) real-time clock/ calendar with timer1 oscillator 0.38 1 a -40c to +85c v dd = 2.0v sleep mode 32.768 khz, t1oscen = 1 , lpt1osc = 0 0.55 1 a -40c to +85c v dd = 3.3v d027 ( i lcd ) lcd module 0.6 4 a -40c to +85c v dd = 3.3v lcd external/internal, 1/8 mux, 1/3 bias ( 2 , 3 ) 6 30 a -40c to +85c v dd = 2.0v lcd charge pump, 1/8 mux, 1/3 bias ( 2 , 4 ) 7 40 a -40c to +85c v dd = 3.3v d028 ( i adrc ) a/d with rc 330 500 a -40c to +85c v dd = 2.0v 385 500 a -40c to +85c v dd = 3.3v d028 ( i usb ) usb module 1 2 ma -40c to +85c v dd and v usb 3 v 3 = 3.3v usb enabled, no cable connected; traffic makes a large difference ( 5 ) note 1: data in the typical column is at 3.3v, 25c unless otherwi se stated. parameters are for design guidance only and are not tested. 2: incremental current while the module is enabled and running. 3: lcd is enabled and running, no glas s is connected; the resistor ladder current is not included. 4: lcd is enabled and running, no glass is connected. 5: this is the module differential current when the usb modul e is enabled and clocked at 48 mhz, but with no usb cable attached. when the usb cable is attached, or data is being tr ansmitted, the current consumption may be much higher (see section 27.6.4 ?usb transceiver current consumption? ). during usb suspend mode (usben = 1 , suspnd = 1 , bus in idle state), the usb module current will be dominated by the d+ or d- pull-up resistor. the integrated pull-up resistors use ?resistor switching? according to the resistor_ecn supplement to the ? usb 2.0 specification ? and therefore, may be as low as 900 ? during idle conditions. dc characteristics standard operating conditions: 3.0v < v dd < 3.6v -40c ? t a ? +85c for industrial (unless otherwise stated) param no. sym characteristic min typ max units conditions v bt operating voltage 2.0 ? 3.6 v battery connected to v bat pin v btadc v bat a/d monitoring voltage specification ( 1 ) 1.6 ? 3.6 v a/d monitoring the v bat pin using the internal a/d channel note 1: measure a/d value using the a/d represented by the equation (measured voltage = ((v bat /2)/v dd ) * 1024) for 10-bit a/d; measured voltage = ((v bat /2)/v dd ) * 4096) for 12-bit a/d.
pic18f97j94 family ds30575a-page 636 ? 2012 microchip technology inc. table 31-7: d c characteristics: power-down and supply current pic18f97j94 family (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ? ta ? +85c for industrial param no. sym characteristic min max units conditions d031 d031a d031b d032 d033 d033a d034 v il input low voltage all i/o ports: schmitt trigger buffer rc3 and rc4 mclr osc1 osc1 sosci vss vss vss vss vss vss vss 0.2 v dd 0.3 v dd 0.8 0.2 v dd 0.2 v dd 0.2 v dd 0.3 v dd v v v v v v v 2v ? v dd ?? 3.6v i 2 c? enabled smbus enabled lp, ms, hs modes ec modes d041 d041a d041b d042 d043 d043a d044 v ih input high voltage all i/o ports: schmitt trigger buffer rc3 and rc4 mclr osc1 osc1 sosci 0.8 0.7 v dd 2.1 0.8 v dd 0.9 v dd 0.7 v dd 0.7 v dd 5.5 5.5 5.5 v dd v dd v dd v dd v v v v v v v 2v ? v dd ? 3.6v i 2 c? enabled smbus enabled rc mode hs mode d060 d061 d063 i il input leakage current ( 1 ) i/o ports mclr osc1 50 ? ? 500 500 1 na na a vss ? v pin ?? v dd pin at high-impedance vss ?? v pin ?? v dd vss ?? v pin ?? v dd d070 i pu weak pull-up current weak pull-up current 50 400 a v dd = 3.6v, v pin = vss d080 d083 v ol output low voltage i/o ports: all ports osc2/clko (ec modes) ? ? ? ? 0.4 0.4 0.4 0.4 v v v v i ol = 6.6 ma, v dd = 3.6v i ol = 5.0 ma, v dd = 2v i ol = 6.6 ma, v dd = 3.6v i ol = 5.0 ma, v dd = 2v d090 d092 v oh output high voltage ( 1 ) i/o ports: all ports osc2/clko (intosc, ec modes) 3.0 2.4 1.6 1.4 2.4 1.4 ? ? ? ? ? ? v v v v v v i oh = -3.0 ma, v dd = 3.6v i oh = -6.0 ma, v dd = 3.6v i oh = -1.0 ma, v dd = 2v i oh = -3.0 ma, v dd = 2v i oh = -6.0 ma, v dd = 3.6v i oh = -1.0 ma, v dd = 2v d100 d101 d102 cosc2 c io c b capacitive loading specs on output pins osc2 pin all i/o pins and osc2 sclx, sdax ? ? ? 20 50 400 pf pf pf in hs mode when external clock is used to drive osc1 to meet the ac timing specifications i 2 c? specification note 1: negative current is defined as current sourced by the pin.
? 2012 microchip technology inc. ds30575a-page 637 pic18f97j94 family table 31-8: dc characteristics: ct mu current source specifications table 31-9: memory programming requirements dc characteristics standard operating conditions: 2v to 3.6v operating temperature -40c ? t a ? +85c for industrial param no. sym characteristic min typ ( 1 ) max units conditions i out 1 ctmu current source, base range ? 550 ? na ctmucon1<1:0> = 01 i out 2 ctmu current source, 10x range ?5.5? ? a ctmucon1<1:0> = 10 i out 3 ctmu current source, 100x range ?55? ? a ctmucon1<1:0> = 11 note 1: nominal value at center point of current trim range (ctmucon1<7:2> = 000000 ). dc characteristics standard operating conditions operating temperature -40c ? t a ? +85c for industrial param no. sym characteristic min typ ? max units conditions internal program memory programming specifications ( 1 ) d110 v pp voltage on mclr /v pp pin v dd + 1.5 ? 10 v (note 2 , note 3 ) d113 i ddp supply current during programming ??10ma program flash memory d130 e p cell endurance 1k 20k ? e/w -40 ? c to +85 ? c d131 v pr v dd for read 2?3.6v d132b v pew voltage for self-timed erase or write operations v dd 2 ? 3.6 v pic18fxxkxx devices d133a t iw self-timed write cycle time ? 2 ? ms d133b t ie self-timed block erased cycle time ?33?ms d134 t retd characteristic retention 10 ? ? year provided no other specifications are violated d135 i ddp supply current during programming ??10ma d140 t we writes per erase cycle ? ? 1 for each physical address ? data in ?typ? column is at 3.3v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: these specifications are for programming the on-chip program memory through the use of table write instructions. 2: required only if single-supply programming is disabled. 3: the mplab ? icd 2 does not support variable v pp output. circuitry to limit the mplab icd 2 v pp voltage must be placed between the mplab icd 2 and the target system when programming or debugging with the mplab icd 2.
pic18f97j94 family ds30575a-page 638 ? 2012 microchip technology inc. table 31-10: comparator specifications table 31-11: comparator voltag e reference specifications table 31-12: internal voltag e regulator specification s table 31-13: rc oscillator start-up time operating conditions: 2.0v ? v dd ? 3.6v, -40c ? t a ? +85c param no. sym characteristics min typ max units comments d300 v ioff input offset voltage ? 5.0 40 mv d301 v icm input common-mode voltage 0 ? av dd v d302 cmrr common-mode rejection ratio 55 ? ? db d303 t resp response time ( 1 ) ?150400 ns d304 t mc 2 ov comparator mode change to output valid* ?? 10 ? s note 1: response time is measured with one comparator input at (av dd ? 1.5)/2, while the other input transitions from v ss to v dd . operating conditions: 2.0v ? v dd ? 3.6v, -40c ? t a ? +85c param no. sym characteristics min typ max units comments d310 v res resolution v dd /32 ? v dd /32 lsb d311 vr aa absolute accuracy ? ? 3/4 lsb d312 vr ur unit resistor value (r) ? 2k ? ? d313 t set settling time ( 1 ) ? ? 10 ? s note 1: settling time measured while cvrr = 1 and cvr<3:0> transitions from ? 0000 ? to ? 1111 ?. operating conditions: -40c ? t a ? +85c param no. sym characteristics min typ max units comments v rgout regulator output voltage ? 1.8 ? v c efc external filter capacitor value 4.7 10 ? ? f capacitor must be low-esr, a low series resistance (< 5 ? ) ac characteristics standard operating conditions: 2v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial param no. characteristics min typ max units comments t frc ?15?s t lprc ?10?s
? 2012 microchip technology inc. ds30575a-page 639 pic18f97j94 family table 31-14: usb mo dule specifications operating conditions: -40c pic18f97j94 family ds30575a-page 640 ? 2012 microchip technology inc. 31.3 ac (timing) characteristics 31.3.1 timing parameter symbology the timing parameter symbols have been created following one of the following formats: 1. tpps2pps 3. t cc : st (i 2 c specifications only) 2. tpps 4. ts (i 2 c specifications only) t f frequency t time lowercase letters (pp) and their meanings: pp cc ccp1 osc osc1 ck clko rd rd cs cs rw rd or wr di sdi sc sck do sdo ss ss dt data in t0 t0cki io i/o port t1 t1cki mc mclr wr wr uppercase letters and their meanings: s f fall p period hhigh rrise i invalid (high-impedance) v valid l low z high-impedance i 2 c only aa output access high high buf bus free low low t cc : st (i 2 c specifications only) cc hd hold su setup st dat data input hold sto stop condition sta start condition
? 2012 microchip technology inc. ds30575a-page 641 pic18f97j94 family 31.3.2 timing conditions the temperature and voltages specified in table 31-15 apply to all timing specifications unless otherwise noted. figure 31-2 specifies the load conditions for the timing specifications. table 31-15: temperature and voltage specifications ? ac figure 31-2: load conditions for device timing specifications ac characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ?? +85c for industrial operating voltage v dd range as described in section 31.1 and section table 31- 1: . v dd /2 c l r l pin pin v ss v ss c l r l = 464 ? c l = 50 pf for all pins except osc2/clko/ra6 and including d and e outputs as ports c l = 20 pf for osc2/clko/ra6 load condition 1 load condition 2
pic18f97j94 family ds30575a-page 642 ? 2012 microchip technology inc. 31.3.3 timing diagrams and specifications figure 31-3: external clock timing table 31-16: external cl ock timing requirements param. no. symbol characteristic min max units conditions 1a f osc external clkin frequency (1) dc 64 mhz ec oscillator mode oscillator frequency ( 1 ) 4 16 mhz hs oscillator mode 4 16 mhz hs + pll oscillator mode 1t osc external clkin period ( 1 ) 15.6 ? ns ec, ecio oscillator mode oscillator period ( 1 ) 40 250 ns hs oscillator mode 62.5 250 ns hs+pll oscillator mode 2t cy instruction cycle time ( 1 ) 62.5 ? ns t cy = 4/f osc 3t os l, t os h external clock in (osc1) high or low time 10 ? ns hs oscillator mode 4t os r, t os f external clock in (osc1) rise or fall time ? 7.5 ns hs oscillator mode note 1: instruction cycle period (t cy ) equals four times the input oscillator time base period for all configurations except pll. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min.? values with an external clock applied to the osc1/clkin pin. when an external clock input is used, the ?max.? cycle time limit is ?dc? (no clock) for all devices. osc1 clko q4 q1 q2 q3 q4 q1 1 2 3 3 4 4
? 2012 microchip technology inc. ds30575a-page 643 pic18f97j94 family table 31-17: pll clock ti ming specifications (v dd = 2.0v to 3.6v) ( 1 ) table 31-18: internal rc accuracy (frc) param no. sym characteristic min typ max units conditions f10 f osc oscillator frequency range 4?16mhzv dd = 2.0-3.6v, -40c to +85c f11 f sys on-chip vco system frequency 16 ? 64 mhz v dd = 2.0-3.6v, -40c to +85c f12 t rc pll start-up time (lock time) ? ? 2 ms f13 ? clk clkout stability (jitter) -2 ? +2 % note 1: these specifications are for x96 pll or x8 pll. pic18f97j94 standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c param no. characteristics min typ max units conditions oa1 frc accuracy @ freq = 8 mhz, 4 mhz, 2 mhz, 1 mhz, 500 khz, 250 khz, 125 khz, 31.25 khz ( 1 ) -0.5 ? +0.5 % +25c v dd = 3.0-3.6v -1.5 ? +1.5 % -40c to +85c v dd = 2.0-3.6v oa2 lprc accuracy @ freq = 31 khz -20 ? 20 % -40c to +85c v dd = 2.0-3.6v note 1: frequency is calibrated at +25c. osctune register can be used to compensate for temperature drift.
pic18f97j94 family ds30575a-page 644 ? 2012 microchip technology inc. figure 31-4: clko and i/o timing table 31-19: clko and i/o timing requirements param no. symbol characteristic min typ max units conditions 10 t os h2 ck losc1 ? to clko ? ?75200ns (note 1 ) 11 t os h2 ck hosc1 ? to clko ? ?75200ns (note 1 ) 12 t ck rclko rise time ? 15 30 ns (note 1 ) 13 t ck fclko fall time ? 15 30 ns (note 1 ) 14 t ck l2 io vclko ? to port out valid ? ? 0.5 t cy + 20 ns 15 t io v2 ck h port in valid before clko ? 0.25 t cy + 25 ? ? ns 16 t ck h2 io i port in hold after clko ? 0??ns 17 t os h2 io vosc1 ? (q1 cycle) to port out valid ? 50 150 ns 18 t os h2 io iosc1 ? (q2 cycle) to port input invalid (i/o in hold time) 100 ? ? ns 19 t io v2 os h port input valid to osc1 ?? (i/o in setup time) 0??ns 20 t io r port output rise time ? 10 25 ns 21 t io f port output fall time ? 10 25 ns 22 ? t inp intx pin high or low time 20 ? ? ns 23 ? t rbp rb<7:4> change intx high or low time t cy ??ns ? these parameters are asynchronous events not related to any internal clock edges. note 1: measurements are taken in ec mode, where clko output is 4 x t osc . note: refer to figure 31-2 for load conditions. osc1 clko i/o pin (input) i/o pin (output) q4 q1 q2 q3 10 13 14 17 20, 21 19 18 15 11 12 16 old value new value
? 2012 microchip technology inc. ds30575a-page 645 pic18f97j94 family figure 31-5: program memory fe tch timing diagram (8-bit) table 31-20: program me mory fetch timing requirements (8-bit) param no symbol characteristics min typ max units 150 tadv2ail address out valid to ale ? (address setup time) 0.25 t cy ? 10 ? ? ns 151 tail2adl ale ? to address out invalid (address hold time) 5 ? ? ns 153 b a 01 ba0 ? to most significant data valid 0.125 t cy ??ns 154 b a 02 ba0 ? to least significant data valid 0.125 t cy ??ns 155 tail2oel ale ? to oe ? 0.125 t cy ??ns 161 toeh2add oe ? to a/d driven 0.125 t cy ? 5 ? ? ns 162 tadv2oeh least significant data valid before oe ? (data setup time) 20 ? ? ns 162a tadv2oeh most significant data valid before oe ? (data setup time) 0.25 t cy + 20 ? ? ns 163 toeh2adi oe ? to data in invalid (data hold time) 0 ? ? ns 166 taih2aih ale ? to ale ? (cycle time) ? t cy ?ns 167 t acc address valid to data valid 0.5 t cy ? 10 ? ? ns 168 toe oe ? to data valid ? ? 0.125 t cy + 5 ns 170 tubh2oeh ba0 = 0 valid before oe ? 0.25 t cy ??ns 170a tubl2oeh ba0 = 1 valid before oe ? 0.5 t cy ??ns q1 q2 q3 q4 q1 q2 osc1 ale oe address data 170 161 162 ad<7:0> address address a<19:8> address 162a ba0 data 170a 151 150 166 167 155 153 163 154 168 ce note: fmax = 25 mhz in 8-bit external memory mode.
pic18f97j94 family ds30575a-page 646 ? 2012 microchip technology inc. figure 31-6: program memo ry read timing diagram table 31-21: clko and i/o timing requirements param. no symbol characteristics min typ max units 150 tadv2all address out valid to ale ?? (address setup time) 0.25 t cy ? 10 ? ? ns 151 tall2adl ale ? to address out invalid (address hold time) 5??ns 155 tall2oel ale ?? to oe ? 10 0.125 t cy ?ns 160 tadz2oel a/d high-z to oe ?? (bus release to oe )0??ns 161 toeh2add oe ? to a/d driven 0.125 t cy ? 5 ? ? ns 162 tadv2oeh ls data valid before oe ?? (data setup time) 20 ? ? ns 163 toeh2adl oe ? to data in invalid (data hold time) 0 ? ? ns 164 talh2all ale pulse width ? 0.25 t cy ?ns 165 toel2oeh oe pulse width 0.5 t cy ? 5 0.5 t cy ?ns 166 talh2alh ale ? to ale ? (cycle time) ? t cy ?ns 167 tacc address valid to data valid 0.75 t cy ? 25 ? ? ns 168 toe oe ? to data valid ? 0.5 t cy ? 25 ns 169 tall2oeh ale ?? to oe ? 0.625 t cy ? 10 ? 0.625 t cy + 10 ns 171 talh2csl chip enable active to ale ? 0.25 t cy ? 20 ? ? ns 171a tubl2oeh a/d valid to chip enable active ? ? 10 ns q1 q2 q3 q4 q1 q2 osc1 ale oe address data from external 166 160 165 161 151 162 163 ad<15:0> 168 155 address address 150 a<19:16> address ba0 ce 171 171a operating conditions: 2.0v < v cc < 3.6v, -40c < t a < +125c unless otherwise stated. 164 167 169
? 2012 microchip technology inc. ds30575a-page 647 pic18f97j94 family figure 31-7: reset, watchdog timer, oscillator start-up timer and power-up timer timing figure 31-8: brown-out reset timing table 31-22: reset, watchdog timer, oscill ator start-up timer, power-up timer and brown-out reset requirements param. no. symbol characteristic min typ max units conditions 30 tmcl mclr pulse width (low) 2 ? ? ? s 31 t wdt watchdog timer time-out period (no postscaler) ?4.00? ms 32 t ost oscillation start-up timer period 1024 t osc ? 1024 t osc ?t osc = osc1 period 33 t pwrt power-up timer period ? 300 s ? ? s 34 t ioz i/o high-impedance from mclr low or watchdog timer reset ?2? ? s 35 t bor brown-out reset pulse width 200 ? ? ? sv dd ? bv dd (see d005) 36 t irvst time for internal reference voltage to become stable ?25? ? s 37 t hlvd high/low-voltage detect pulse width 200 ? ? ? sv dd ? v hlvd 38 t csd cpu start-up time 5 ? 10 ? s 39 t iobst time for intosc to stabilize ? 1 ? ? s v dd mclr internal por pwrt time-out oscillator time-out internal reset watchdog timer reset 33 32 30 31 34 i/o pins 34 note: refer to figure 31-2 for load conditions. v dd bv dd 35 v bgap = 1.2v v irvst enable internal internal reference 36 reference voltage voltage stable
pic18f97j94 family ds30575a-page 648 ? 2012 microchip technology inc. figure 31-9: high/low-volta ge detect characteristics table 31-23: high/low-voltage detect characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial param no. sym characteristic min typ max units conditions d420 hlvd voltage on v dd transition high-to-low hlvdl<3:0> = 0100 2.0 ? 2.2 v hlvdl<3:0> = 0101 2.1 ? 2.3 v hlvdl<3:0> = 0110 2.2 ? 2.4 v hlvdl<3:0> = 0111 2.3 ? 2.5 v hlvdl<3:0> = 1000 2.4 ? 2.6 v hlvdl<3:0> = 1001 2.5 ? 2.75 v hlvdl<3:0> = 1010 2.7 ? 2.95 v hlvdl<3:0> = 1011 2.8 ? 3.1 v hlvdl<3:0> = 1100 3.0 ? 3.3 v hlvdl<3:0> = 1101 3.3 ? 3.6 v hlvdl<3:0> = 1110 3.45 ? 3.75 v v hlvd hlvdif v dd (hlvdif set by hardware) (hlvdif can be cleared in software) v hlvd for vdirmag = 1 : for vdirmag = 0 : v dd
? 2012 microchip technology inc. ds30575a-page 649 pic18f97j94 family figure 31-10: timer0 and timer1 external clock timings table 31-24: timer0 and timer1 external clock requirements param no. symbol characteristic min max units conditions 40 t t 0h t0cki high pulse width no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 41 t t 0l t0cki low pulse width no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 42 t t 0p t0cki period no prescaler t cy + 10 ? ns with prescaler greater of: 20 ns or (t cy + 40)/n ?nsn = prescale value (1, 2, 4,..., 256) 45 t t 1h t1cki high time synchronous, no prescaler 0.5 t cy + 20 ? ns synchronous, with prescaler 10 ? ns asynchronous 30 ? ns 46 t t 1l t1cki low time synchronous, no prescaler 0.5 t cy + 5 ? ns synchronous, with prescaler 10 ? ns asynchronous 30 ? ns 47 t t 1p t1cki input period synchronous greater of: 20 ns or (t cy + 40)/n ?nsn = prescale value (1, 2, 4, 8) asynchronous 60 ? ns f t 1 t1cki oscillator input frequency range dc 50 khz 48 t cke 2 tmr i delay from external t1cki clock edge to timer increment 2 t osc 7 t osc ? note: refer to figure 31-2 for load conditions. 46 47 45 48 41 42 40 txcki sosco/sclki tmr0 or tmr1
pic18f97j94 family ds30575a-page 650 ? 2012 microchip technology inc. figure 31-11: capture/compare/pwm timings (ccp1, ccp2 modules) table 31-25: capture/compare/pwm re quirements (ccp1, ccp2 modules) param no. symbol characteristic min max units conditions 50 t cc l ccpx input low time no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 51 t cc h ccpx input high time no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 52 t cc p ccpx input period 3 t cy + 40 n ? ns n = prescale value (1, 4 or 16) 53 t cc r ccpx output fall time ? 25 ns 54 t cc f ccpx output fall time ? 25 ns note: refer to figure 31-2 for load conditions. ccpx (capture mode) 50 51 52 ccpx 53 54 (compare or pwm mode)
? 2012 microchip technology inc. ds30575a-page 651 pic18f97j94 family figure 31-12: example spi master mode timing (cke = 0 ) table 31-26: example spi mode requirements (master mode, cke = 0 ) param no. symbol characteristic min max units conditions 73 t di v2 sc h, t di v2 sc l setup time of sdix data input to sckx edge 20 ? ns 73a t b 2 b last clock edge of byte 1 to the 1st clock edge of byte 2 1.5 t cy + 40 ? ns 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 40 ? ns 75 t do r sdox data output rise time ? 25 ns 76 t do f sdox data output fall time ? 25 ns 78 t sc r sckx output rise time (master mode) ? 25 ns 79 t sc f sckx output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdox data output valid after sckx edge ? 50 ns sckx (ckpx = 0 ) sckx (ckpx = 1 ) sdox sdix 73 74 75, 76 78 79 80 79 78 msb lsb bit 6 - - - - - - 1 lsb in bit 6 - - - - 1 note: refer to figure 31-2 for load conditions. msb in
pic18f97j94 family ds30575a-page 652 ? 2012 microchip technology inc. figure 31-13: example spi master mode timing (cke = 1 ) table 31-27: example spi mode requirements (master mode, cke = 1 ) param. no. symbol characteristic min max units conditions 73 t di v2 sc h, t di v2 sc l setup time of sdix data input to sckx edge 20 ? ns 73a t b 2 b last clock edge of byte 1 to the 1st clock edge of byte 2 1.5 t cy + 40 ? ns 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 40 ? ns 75 t do r sdox data output rise time ? 25 ns 76 t do f sdox data output fall time ? 25 ns 78 t sc r sckx output rise time (master mode) ? 25 ns 79 t sc f sckx output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdox data output valid after sckx edge ? 50 ns 81 t do v2 sc h, t do v2 sc l sdox data output setup to sckx edge t cy ?ns sckx (ckpx = 0 ) sckx (ckpx = 1 ) sdox sdix 81 74 75, 76 78 80 msb 79 73 bit 6 - - - - - - 1 lsb in bit 6 - - - - 1 lsb note: refer to figure 31-2 for load conditions. msb in
? 2012 microchip technology inc. ds30575a-page 653 pic18f97j94 family figure 31-14: example spi slave mode timing (cke = 0 ) table 31-28: example spi mode requirements (slave mode timing, cke = 0 ) param no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ssx ? to sckx ? or sckx ? input 3 t cy ?ns 70a t ss l2wb ssx to write to sspbuf 3 t cy ?ns 71 t sc h sckx input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1 ) 72 t sc l sckx input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1 ) 73 t di v2 sc h, t di v2 sc l setup time of sdix data input to sckx edge 20 ? ns 73a t b 2 b last clock edge of byte 1 to the first clock edge of byte 2 1.5 t cy + 40 ? ns (note 2 ) 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 40 ? ns 75 t do r sdox data output rise time ? 25 ns 76 t do f sdox data output fall time ? 25 ns 77 t ss h2 do z ssx ? to sdox output high-impedance 10 50 ns 78 t sc r sckx output rise time (master mode) ? 25 ns 79 t sc f sckx output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdox data output valid after sckx edge ? 50 ns 83 t sc h2 ss h, t sc l2 ss h ssx ? after sckx edge 1.5 t cy + 40 ? ns note 1: requires the use of parameter # 73a . 2: only if parameter # 71a and # 72a are used. ssx sckx (ckpx = 0 ) sckx (ckp = 1 ) sdox sdix 70 71 72 73 74 75, 76 77 78 79 80 79 78 msb lsb bit 6 - - - - - - 1 bit 6 - - - - 1 lsb in 83 note: refer to figure 31-2 for load conditions. msb in
pic18f97j94 family ds30575a-page 654 ? 2012 microchip technology inc. figure 31-15: example spi slave mode timing (cke = 1 ) table 31-29: example spi slave mode requirements (cke = 1 ) param no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ssx ? to sckx ? or sckx ? input 3 t cy ?ns 70a t ss l2wb ssx to write to sspbuf 3 t cy ?ns 71 t sc h sckx input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1 ) 72 t sc l sckx input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1 ) 73a t b 2 b last clock edge of byte 1 to the first clock edge of byte 2 1.5 t cy + 40 ? ns (note 2 ) 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 40 ? ns 75 t do r sdox data output rise time ? 25 ns 76 t do f sdox data output fall time ? 25 ns 77 t ss h2 do z ssx ? to sdox output high-impedance 10 50 ns 78 t sc r sckx output rise time (master mode) ? 25 ns 79 t sc f sckx output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdox data output valid after sckx edge ? 50 ns 82 t ss l2 do v sdox data output valid after ssx ? edge ? 50 ns 83 t sc h2 ss h, t sc l2 ss h ssx ? after sckx edge 1.5 t cy + 40 ? ns note 1: requires the use of parameter # 73a . 2: only if parameter # 71a and # 72a are used. ssx sckx (ckpx = 0 ) sckx (ckpx = 1 ) sdox sdix 70 71 72 82 74 75, 76 msb bit 6 - - - - - - 1 lsb 77 bit 6 - - - - 1 lsb in 80 83 note: refer to figure 31-2 for load conditions. msb in
? 2012 microchip technology inc. ds30575a-page 655 pic18f97j94 family figure 31-16: i 2 c? bus start/stop bits timing table 31-30: i 2 c? bus start/stop bits requirements (slave mode) param. no. symbol characteristic min max units conditions 90 t su : sta start condition 100 khz mode 4700 ? ns only relevant for repeated start condition setup time 400 khz mode 600 ? 91 t hd : sta start condition 100 khz mode 4000 ? ns after this period, the first clock pulse is generated hold time 400 khz mode 600 ? 92 t su : sto stop condition 100 khz mode 4700 ? ns setup time 400 khz mode 600 ? 93 t hd : sto stop condition 100 khz mode 4000 ? ns hold time 400 khz mode 600 ? note: refer to figure 31-2 for load conditions. 91 92 93 sclx sdax start condition stop condition 90
pic18f97j94 family ds30575a-page 656 ? 2012 microchip technology inc. figure 31-17: i 2 c? bus data timing table 31-31: i 2 c? bus data requirements (slave mode) param. no. symbol characteristic min max units conditions 100 t high clock high time 100 khz mode 4.0 ? ? s 400 khz mode 0.6 ? ? s msspx module 1.5 t cy ? 101 t low clock low time 100 khz mode 4.7 ? ? s 400 khz mode 1.3 ? ? s msspx module 1.5 t cy ? 102 t r sdax and sclx rise time 100 khz mode ? 1000 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10 to 400 pf 103 t f sdax and sclx fall time 100 khz mode ? 300 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10 to 400 pf 90 t su : sta start condition setup time 100 khz mode 4.7 ? ? s only relevant for repeated start condition 400 khz mode 0.6 ? ? s 91 t hd : sta start condition hold time 100 khz mode 4.0 ? ? s after this period, the first clock pulse is generated 400 khz mode 0.6 ? ? s 106 t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 ? s 107 t su : dat data input setup time 100 khz mode 250 ? ns (note 2 ) 400 khz mode 100 ? ns 92 t su : sto stop condition setup time 100 khz mode 4.7 ? ? s 400 khz mode 0.6 ? ? s 109 t aa output valid from clock 100 khz mode ? 3500 ns (note 1 ) 400 khz mode ? ? ns 110 t buf bus free time 100 khz mode 4.7 ? ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? ? s d102 c b bus capacitive loading ? 400 pf note 1: as a transmitter, the device must provide this internal minimum delay time to bridge the undefined region (min. 300 ns) of the falling edge of sclx to avoid unintended generation of start or stop conditions. 2: a fast mode i 2 c? bus device can be used in a standard mode i 2 c bus system, but the requirement, t su : dat ? 250 ns, must then be met. this will automatically be the case if the device does not stretch the low period of the sclx signal. if such a device does stretch the low period of the sclx signal, it must output the next data bit to the sdax line, t r max. + t su : dat = 1000 + 250 = 1250 ns (according to the standard mode i 2 c bus specification), before the sclx line is released. note: refer to figure 31-2 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 sclx sdax in sdax out
? 2012 microchip technology inc. ds30575a-page 657 pic18f97j94 family figure 31-18: msspx i 2 c? bus start/stop bits timing waveforms table 31-32: msspx i 2 c? bus start/stop bits requirements figure 31-19: msspx i 2 c? bus data timing param. no. symbol characteristic min max units conditions 90 t su : sta start condition 100 khz mode 2(t osc )(brg + 1) ? ns only relevant for repeated start condition setup time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode ( 1 ) 2(t osc )(brg + 1) ? 91 t hd : sta start condition 100 khz mode 2(t osc )(brg + 1) ? ns after this period, the first clock pulse is generated hold time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode ( 1 ) 2(t osc )(brg + 1) ? 92 t su : sto stop condition 100 khz mode 2(t osc )(brg + 1) ? ns setup time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode ( 1 ) 2(t osc )(brg + 1) ? 93 t hd : sto stop condition 100 khz mode 2(t osc )(brg + 1) ? ns hold time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode ( 1 ) 2(t osc )(brg + 1) ? note 1: maximum pin capacitance = 10 pf for all i 2 c? pins. note: refer to figure 31-2 for load conditions. 91 93 sclx sdax start condition stop condition 90 92 note: refer to figure 31-2 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 sclx sdax in sdax out
pic18f97j94 family ds30575a-page 658 ? 2012 microchip technology inc. table 31-33: msspx i 2 c? bus data requirements param. no. symbol characteristic min max units conditions 100 t high clock high time 100 khz mode 2(t osc )(brg + 1) ? ? 400 khz mode 2(t osc )(brg + 1) ? ? 1 mhz mode ( 1 ) 2(t osc )(brg + 1) ? ? 101 t low clock low time 100 khz mode 2(t osc )(brg + 1) ? ? 400 khz mode 2(t osc )(brg + 1) ? ? 1 mhz mode ( 1 ) 2(t osc )(brg + 1) ? ? 102 t r sdax and sclx rise time 100 khz mode ? 1000 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode ( 1 ) ? 300 ns 103 t f sdax and sclx fall time 100 khz mode ? 300 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode ( 1 ) ? 100 ns 90 t su : sta start condition setup time 100 khz mode 2(t osc )(brg + 1) ? ? only relevant for repeated start condition 400 khz mode 2(t osc )(brg + 1) ? ? 1 mhz mode ( 1 ) 2(t osc )(brg + 1) ? ? 91 t hd : sta start condition hold time 100 khz mode 2(t osc )(brg + 1) ? ? after this period, the first clock pulse is generated 400 khz mode 2(t osc )(brg + 1) ? ? 1 mhz mode ( 1 ) 2(t osc )(brg + 1) ? ? 106 t hd : dat data input hold time 100 khz mode 0 ? ? 400 khz mode 0 0.9 ? s 1 mhz mode ( 1 ) ? ? sns 107 t su : dat data input setup time 100 khz mode 250 ? ns (note 2 ) 400 khz mode 100 ? ns 1 mhz mode ( 1 ) ??ns 92 t su : sto stop condition setup time 100 khz mode 2(t osc )(brg + 1) ? ? 400 khz mode 2(t osc )(brg + 1) ? ? 1 mhz mode ( 1 ) 2(t osc )(brg + 1) ? ? 109 t aa output valid from clock 100 khz mode ? 3500 ns 400 khz mode ? 1000 ns 1 mhz mode ( 1 ) ??ns 110 t buf bus free time 100 khz mode 4.7 ? ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? ? s 1 mhz mode ( 1 ) ?? ? s d102 c b bus capacitive loading ? 400 pf note 1: maximum pin capacitance = 10 pf for all i 2 c? pins. 2: a fast mode i 2 c bus device can be used in a standard mode i 2 c bus system, but parameter #107 ? 250 ns must then be met. this will automatically be the case if the device does not stretch the low period of the sclx signal. if such a device does stretch the low period of the sclx signal, it must output the next data bit to the sdax line, parameter #102 + parameter #107 = 1000 + 250 = 1250 ns (for 100 khz mode), before the sclx line is released.
? 2012 microchip technology inc. ds30575a-page 659 pic18f97j94 family figure 31-20: eusartx synchronous transmission (master/slave) timing table 31-34: eusartx/ausart x synchronous transmission requirements figure 31-21: eusartx/ausartx synchronous receive (master/slave) timing table 31-35: eusartx/ausart x synchronous receive requirements param no. symbol characteristic min max units conditions 120 t ck h2 dt v sync xmit (master and slave) clock high to data out valid ? 40 ns 121 t ckrf clock out rise time and fall time (master mode) ? 20 ns 122 t dtrf data out rise time and fall time ? 20 ns param. no. symbol characteristic min max units conditions 125 t dt v2 ckl sync rcv (master and slave) data hold before ckx ? (dtx hold time) 10 ? ns 126 t ck l2 dtl data hold after ckx ? (dtx hold time) 15 ? ns 121 121 120 122 txx/ckx rxx/dtx pin pin note: refer to figure 31-2 for load conditions. 125 126 txx/ckx rxx/dtx pin pin note: refer to figure 31-2 for load conditions.
pic18f97j94 family ds30575a-page 660 ? 2012 microchip technology inc. table 31-36: a/d converter characteristics: pic18f97j94 (industrial) param no. sym characteristic min typ max units conditions a01 n r resolution ? ? 12 bit ? v ref ? 2.0v a03 e il integral linearity error ? <1 2.0 lsb v dd = 3.0v ( ? v ref ?? 2.0v) a04 e dl differential linearity error ? <1 +2.0/-1.0 lsb v dd = 3.0v ( ? v ref ?? 2.0v) a06 e off offset error ? <1 5 lsb v dd = 3.0v ( ? v ref ?? 2.0v) a07 e gn gain error ? <1 5 lsb v dd = 3.0v ( ? v ref ?? 2.0v) a10 ? monotonicity ( 1 ) ?v ss ? v ain ? v ref a20 ? v ref reference voltage range (v refh ? v refl ) 2?v dd ? v ss v for 12-bit resolution a21 v refh reference voltage high av ss + 2.0v ? av dd + 0.3v v for 12-bit resolution a22 v refl reference voltage low av ss ? 0.3v ? av dd ? 2.0v v for 12-bit resolution a25 v ain analog input voltage v refl ?v refh v a28 av dd analog supply voltage v dd ? 0.3 ? v dd + 0.3 v a29 av ss analog supply voltage v ss ? 0.3 ? v ss + 0.3 v a30 z ain recommended impedance of analog voltage source ??2.5k ? a50 i ref v ref input current ( 2 ) ? ? ? ? 5 150 ? a ? a during v ain acquisition. during a/d conversion cycle. note 1: the a/d conversion result never decreas es with an increase in the input voltage. 2: v refh current is from the ra3/an3/v ref + pin or v dd , whichever is selected as the v refh source. v refl current is from the ra2/an2/v ref -/cv ref pin or v ss , whichever is selected as the v refl source.
? 2012 microchip technology inc. ds30575a-page 661 pic18f97j94 family figure 31-22: a/d conversion timing table 31-37: a/d conversion requirements param no. symbol characteristic min max units conditions sample start delay from setting samp 2 3 t ad 130 t ad a/d clock period 300 ? ns 250 ? ns a/d rc mode 131 t cnv conversion time (not including acquisition time) ( 2 ) 14 15 t ad 132 t acq acquisition time ( 3 ) ? 750 ns -40c to +85c (5) 135 t swc switching time from convert ? sample ? (note 4 ) t dis discharge time 1 ? t ad -40c to +85c a/d stabilization time (from setting adon to setting samp) 300 ? ns note 1: the time of the a/d clock period is dependent on the device frequency and the t ad clock divider. 2: adres registers may be read on the following t cy cycle. 3: the time for the holding capacitor to acquire the ?new? input voltage when the voltage changes full scale after the conversion (v dd to v ss or v ss to v dd ). the source impedance ( r s ) on the input channels is 50 ? . 4: on the following cycle of the device clock. 5: the time for the holding capacitor to acquire the ?new? input voltage when the voltage changes full scale after the conversion (av dd to av ss or av ss to av dd ). 131 130 132 bsf adcon1l, samp q4 a/d clk a/d data adres adif go sample old_data sampling stopped done new_data (note 2) 11 10 9 2 1 0 note 1: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. 2: this is a minimal rc delay (typically 100 ns), which also disconnects the holding capacitor from the analog input. . . . . . . t cy (note 1)
pic18f97j94 family ds30575a-page 662 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 663 pic18f97j94 family 32.0 packaging information 32.1 package marking information 64-lead qfn (9x9x0.9 mm) example pin 1 xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx yywwnnn pin 1 64-lead tqfp example 18f67j94- i/pt 1210017 3 e xxxxxxxxxx xxxxxxxxxx yywwnnn xxxxxxxxxx 80-lead tqfp example pic18f87j94- i/pt 1210017 3 e xxxxxxxxxxxx xxxxxxxxxxxx yywwnnn 100-lead tqfp (12x12x1 mm) xxxxxxxxxxxx xxxxxxxxxxxx yywwnnn example pic18f97j94- i/pt 1210017 3 e
pic18f97j94 family ds30575a-page 664 ? 2012 microchip technology inc. 100-lead tqfp (14x14x1 mm) example pic18f97j94- i/pf 1210017 legend: xx...x customer-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e 3 e xxxxxxxxxxxx xxxxxxxxxxxx yywwnnn
? 2012 microchip technology inc. ds30575a-page 665 pic18f97j94 family 32.2 package details the following sections give the technical details of the packages. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic18f97j94 family ds30575a-page 666 ? 2012 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2012 microchip technology inc. ds30575a-page 667 pic18f97j94 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic18f97j94 family ds30575a-page 668 ? 2012 microchip technology inc. 
       
     !" #$  %
& '  (   !" # $% &" '  ()"&'"!&)  & #*&&  & #    + '% ! & !  
& ,!- '    ' !! #.#&"# '#% !
&"!!#% !
&"!!! & $ #/''
!#   ' !  #&   
.0/ 1+2 1 !' !  &  $ & " !**&"&&   ! .32  %   ' !("!" *&"&&   (%%' &
"
! ! ' ( 3& '!&" &
4 # * !(
 ! ! & 
 4  
% & & # & &&
255***'
'5
4  6&! 77.. ' !7'&! 8 89 : 8"') %7 #! 8 ; 7 #& /1+ 9  <  &  = =  # # 4 4 !!  /  / & #%%  / = / 3&7  & 7 / ; / 3&
& 7 .3 3&  > /> > 9  ?#& . 1+ 9  7  &  1+ # # 4 ?#& . 1+ # # 4 7  &  1+ 7 #4 !!   =  7 #?#& )    # %&  
> > > # %&  1&&' > > > d d1 e e1 e b n note 1 123 note 2 c l a1 l1 a2 a 
    * + @/1
? 2012 microchip technology inc. ds30575a-page 669 pic18f97j94 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic18f97j94 family ds30575a-page 670 ? 2012 microchip technology inc. )
       
  ##   !" #$  %
& '  (   !" # $% &" '  ()"&'"!&)  & #*&&  & #    + '% ! & !  
& ,!- '    ' !! #.#&"# '#% !
&"!!#% !
&"!!! & $ #/''
!#   ' !  #&   
.0/ 1+2 1 !' !  &  $ & " !**&"&&   ! .32  %   ' !("!" *&"&&   (%%' &
"
! ! ' ( 3& '!&" &
4 # * !(
 ! ! & 
 4  
% & & # & &&
255***'
'5
4  6&! 77.. ' !7'&! 8 89 : 8"') %7 #! 8 @ 7 #& /1+ 9  <  &  = =  # # 4 4 !!  /  / & #%%  / = / 3&7  & 7 / ; / 3&
& 7 .3 3&  > /> > 9  ?#& . 1+ 9  7  &  1+ # # 4 ?#& . 1+ # # 4 7  &  1+ 7 #4 !!   =  7 #?#& )    # %&  
> > > # %&  1&&' > > > d d1 e e1 e b n note 1 123 note 2 a a2 l1 a1 l c 
    * + 1
? 2012 microchip technology inc. ds30575a-page 671 pic18f97j94 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic18f97j94 family ds30575a-page 672 ? 2012 microchip technology inc. 
       
  ##   !" #$  %
& '  (   !" # $% &" '  ()"&'"!&)  & #*&&  & #    + '% ! & !  
& ,!- '    ' !! #.#&"# '#% !
&"!!#% !
&"!!! & $ #/''
!#   ' !  #&   
.0/ 1+2 1 !' !  &  $ & " !**&"&&   ! .32  %   ' !("!" *&"&&   (%%' &
"
! ! ' ( 3& '!&" &
4 # * !(
 ! ! & 
 4  
% & & # & &&
255***'
'5
4  6&! 77.. ' !7'&! 8 89 : 8"') %7 #! 8  7 #& 1+ 9  <  &  = =  # # 4 4 !!  /  / & #%%  / = / 3&7  & 7 / ; / 3&
& 7 .3 3&  > /> > 9  ?#& . 1+ 9  7  &  1+ # # 4 ?#& . 1+ # # 4 7  &  1+ 7 #4 !!   =  7 #?#& )  @  # %&  
> > > # %&  1&&' > > > d d1 e e1 e b n 123 note 1 note 2 c l a1 l1 a a2 
    * + 1
? 2012 microchip technology inc. ds30575a-page 673 pic18f97j94 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic18f97j94 family ds30575a-page 674 ? 2012 microchip technology inc. 
       
     !" #$  %
& '  (   !" # $% &" '  ()"&'"!&)  & #*&&  & #    + '% ! & !  
& ,!- '    ' !! #.#&"# '#% !
&"!!#% !
&"!!! & $ #/''
!#   ' !  #&   
.0/ 1+2 1 !' !  &  $ & " !**&"&&   ! .32  %   ' !("!" *&"&&   (%%' &
"
! ! ' ( 3& '!&" &
4 # * !(
 ! ! & 
 4  
% & & # & &&
255***'
'5
4  6&! 77.. ' !7'&! 8 89 : 8"') %7 #! 8  7 #& /1+ 9  <  &  = =  # # 4 4 !!  /  / & #%%  / = / 3&7  & 7 / ; / 3&
& 7 .3 3&  > /> > 9  ?#& . ;1+ 9  7  &  ;1+ # # 4 ?#& . 1+ # # 4 7  &  1+ 7 #4 !!   =  7 #?#& )    # %&  
> > > # %&  1&&' > > > d d1 e b e1 e n note 1 note 2 123 c l a1 l1 a2 a 
    * + 1
? 2012 microchip technology inc. ds30575a-page 675 pic18f97j94 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic18f97j94 family ds30575a-page 676 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 677 pic18f97j94 family appendix a: revision history revision a (october 2012) original data sheet for pic18f97j94 family devices.
pic18f97j94 family ds30575a-page 678 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 679 pic18f97j94 family index numerics 12-bit a/d converter with threshold scan ...................... 435 a a/d a/d module state machine module ......................... 457 conversion requirements ....................................... 661 converter characteristics ........................................ 660 registers .................................................................. 437 absolute maximum ratings ............................................. 629 ac (timing) characteristics ............................................. 640 load conditions for device timing specifications ... 641 parameter symbology ............................................. 640 temperature and voltage specific ations ................. 641 timing conditions .................................................... 641 ackstat ........................................................................ 401 ackstat status flag ..................................................... 401 active clock tuning (act) module .................................... 59 addfsr .......................................................................... 618 addlw ............................................................................ 581 addulnk ........................................................................ 618 addwf ............................................................................ 581 addwfc ......................................................................... 582 andlw ............................................................................ 582 andwf ............................................................................ 583 assembler mpasm assembler .................................................. 626 auto-wake-up on sync break character ......................... 424 b baud rate generator ....................................................... 397 bc .................................................................................... 583 bcf .................................................................................. 584 bf .................................................................................... 401 bf status flag ................................................................. 401 block diagrams 100-pin devices ......................................................... 16 12-bit a/d converter ................................................ 436 16-bit byte select mode .......................................... 159 16-bit byte write mode ............................................ 157 16-bit word write mode ........................................... 158 64-pin devices ........................................................... 14 80-pin devices ........................................................... 15 8-bit multiplexed mode ............................................ 161 96 mhz pll ............................................................... 54 basic oscillator .......................................................... 53 baud rate generator ............................................... 397 bus power only ....................................................... 546 capture mode operation ................................. 321, 345 comparator analog input model .............................. 492 comparator configurations ...................................... 494 comparator module ................................................. 489 comparator voltage reference ............................... 498 comparator voltage reference output buffer ......... 499 compare mode operation ............................... 322, 347 crystal or ceramic resonator operation (ms or hs) ......................................................... 49 ctmu ....................................................................... 507 ctmu current source calibration circuit ................ 514 ctmu temperature measurement circuit ............... 522 ctmu typical connections and internal configuration for time measurement .............. 521 data signal modulator ............................................. 236 dual power with self-power dominance ................. 546 enhanced pwm mode ............................................. 323 eusartx receive .................................................. 423 eusartx transmit ................................................. 421 external clock input (clkoen = 0) .......................... 52 external clock input (clkoen = 1) .......................... 52 external power-on reset circuit (slow v dd power-up) ........................................ 92 fail-safe clock monitor (fscm) .............................. 571 full-bridge application example .............................. 327 generic i/o port operation ...................................... 197 half-bridge applications .......................................... 333 high/low-voltage detect with external input .......... 502 interrupt logic .......................................................... 169 lcd clock generation ............................................. 251 lcd controller ......................................................... 245 mssp (spi mode) ................................................... 352 msspx (i 2 c master mode) ...................................... 395 msspx (i 2 c mode) .................................................. 372 multiplexing of remappable output for rpn ........... 230 on-chip reset circuit ................................................ 85 pic18f general system clock .................................. 37 port shared with pps peripherals structure ........... 225 portd and porte (parallel slave port) ............... 221 pwm operation (simplified) .................................... 348 reads from flash program memory ....................... 147 remappable input for u1rx ................................... 226 rtcc ....................................................................... 297 rtcc clock source multiplexing ............................ 311 self tuning ................................................................ 60 self-power only ....................................................... 546 simplified steering ................................................... 336 single comparator ................................................... 492 spi master/slave connection .................................. 357 table read operation ............................................. 143 table write operation ............................................. 144 table writes to flash program memory .................. 149 timer0 in 16-bit mode ............................................. 282 timer0 in 8-bit mode ............................................... 282 timer1/3/5 ............................................................... 287 timer2/4/6/8 ............................................................ 295 usb buffer descriptor ............................................. 534 usb external circuitry ............................................. 530 usb interrupt logic ................................................. 540 usb layers ............................................................. 550 usb peripheral and options ................................... 525 using open-drain output (usart) ........................ 199 ustat fifo ............................................................ 531 v bat p ower t opology ............................................. 75 watchdog timer ...................................................... 568 bn .................................................................................... 584 bnc ................................................................................. 585 bnn ................................................................................. 585 bnov .............................................................................. 586 bnz ................................................................................. 586 bor. see brown-out reset. bov ................................................................................. 589 bra ................................................................................. 587 break character (12-bit) transmit and receive .............. 426 brg. see baud rate generator. bsf .................................................................................. 587 btfsc ............................................................................. 588 btfss ............................................................................. 588
pic18f97j94 family ds30575a-page 680 ? 2012 microchip technology inc. btg .................................................................................. 589 bz ..................................................................................... 590 c c compilers mplab c18 ............................................................. 626 call ................................................................................ 590 callw ............................................................................. 619 capture (ccp module) ..................................................... 344 ccpr4h:ccpr4l registers ................................... 344 pin configuration ..................................................... 344 prescaler .................................................................. 345 software interrupt .................................................... 345 timer1/3/5/7 mode selection ................................... 344 capture (eccp module) .................................................. 321 ccprxh:ccprxl registers ................................... 321 eccp pin configuration .......................................... 321 prescaler .................................................................. 321 software interrupt .................................................... 321 timer1/2/3/4/5/6/8 mode selection .......................... 321 capture/compare/pwm (ccp) ........................................ 339 capture mode. see capture. ccp mode and timer resources ............................ 343 ccp6/7/8/9 pin assignment .................................... 344 ccprxh register .................................................... 343 ccprxl register ..................................................... 343 compare mode. see compare. configuration ............................................................ 343 open-drain output option ....................................... 344 charge time measurement unit (ctmu) ........................ 507 calibrating the module ............................................. 513 effects of a reset ..................................................... 523 measuring capacitance ........................................... 519 measuring time ....................................................... 521 module initialization ................................................. 513 operation ................................................................. 512 during sleep, idle modes ................................. 523 temperature measurement ..................................... 522 clock switching considerations ........................................................... 59 clock switching operation ................................................. 57 abandoning ................................................................ 62 enabling ..................................................................... 58 entering sleep mode ................................................. 62 sequence ................................................................... 58 clrf ................................................................................ 591 clrwdt .......................................................................... 591 code examples 16 x 16 signed multiply routine .............................. 166 16 x 16 unsigned multiply routine .......................... 166 512-byte spi master mode init, transfer ............... 370 8 x 8 signed multiply routine .................................. 165 8 x 8 unsigned multiply routine .............................. 165 changing between capture prescalers ........... 321, 345 clearing actvif bit (uir) ....................................... 542 computed goto using an offset value ................. 117 converting 1 channel, manual sample and conversion start .............................................. 462 converting 1 channel, manual sample start, t ad based conversion start ................................... 463 ctmu capacitance calibration routine .................. 518 ctmu routine for capacitive touch switch ............ 520 ctmu routine for temperature measurement using internal diode ........................................ 522 current calibration routine ..................................... 516 erasing a flash program memory row ................... 148 fast register stack ................................................. 117 how to clear ram (bank 1) using indirect addressing ....................................................... 136 initializing porta .................................................... 201 initializing portb .................................................... 203 initializing portc ................................................... 205 initializing portd ................................................... 207 initializing porte .................................................... 209 initializing portf .................................................... 211 initializing portg ................................................... 213 initializing porth ................................................... 215 initializing portj .................................................... 217 initializing portk .................................................... 219 initializing portl .................................................... 220 loading the ssp1buf (ssp1sr) register ............. 356 reading a flash program memory word ................ 147 saving status, wreg and bsr registers in ram ................................................................. 195 setting the rtcwren bit ....................................... 312 setup for ctmu calibration routines ..................... 515 single-word write to flash memory ........................ 151 sleep assembly syntax ........................................... 67 writing to flash program memory ........................... 150 code protection ............................................................... 553 comf .............................................................................. 592 comparator ...................................................................... 489 analog input connection considerations ................ 492 configuration ........................................................... 493 control ..................................................................... 493 effects of a reset .................................................... 496 enable and input selection ...................................... 493 enable and output selection ................................... 493 interrupts ................................................................. 495 operation ................................................................. 492 operation during sleep ........................................... 496 response time ........................................................ 492 comparator specifications ............................................... 638 comparator voltage reference ....................................... 497 accuracy and error .................................................. 499 configuring .............................................................. 497 connection considerations ...................................... 499 effects of a reset .................................................... 499 operation during sleep ........................................... 499 comparator voltage reference specifications ................ 638 compare (ccp module) .................................................. 346 ccp pin configuration ............................................. 346 ccpr4 register ...................................................... 346 software interrupt .................................................... 346 special event trigger .............................................. 346 timer1/3/5 mode selection ...................................... 346 compare (eccp module) ................................................ 322 ccprx register ...................................................... 322 pin configuration ..................................................... 322 software interrupt .................................................... 322 special event trigger ...................................... 293, 322 timer1/2/3/4/5/6/8 mode selection .......................... 322 computed goto ............................................................. 117 configuration bits ............................................................ 553 device ids, summary .............................................. 554 core features ...................................................................... 9 easy migration ........................................................... 10 extended instruction set ........................................... 10 external memory bus (emb) ..................................... 10 memory options ........................................................ 10 universal serial bus (usb) ............................... 10
? 2012 microchip technology inc. ds30575a-page 681 pic18f97j94 family oscillator options and features .................................. 9 cpfseq .......................................................................... 592 cpfsgt .......................................................................... 593 cpfslt ........................................................................... 593 customer change notification service ............................ 691 customer notification service .......................................... 691 customer support ............................................................ 691 d data addressing modes ................................................... 136 comparing addressing modes with the extended instruction set enabled ................... 140 direct ........................................................................ 136 indexed literal offset ............................................... 139 bsr ................................................................. 141 instructions affected ........................................ 139 mapping access bank ..................................... 141 indirect ..................................................................... 136 inherent and literal .................................................. 136 data memory ................................................................... 120 access bank ............................................................ 122 bank select register (bsr) ..................................... 120 extended instruction set .......................................... 139 general purpose registers ...................................... 122 memory maps pic18f97j94 devices ..................................... 121 special function registers (sfrs) .......................... 123 data signal modulator (dsm) .......................................... 235 carrier signal sources ............................................. 237 carrier source pin disable ....................................................... 240 polarity select .................................................. 240 carrier synchronization ........................................... 237 effects of a reset ..................................................... 240 modulated output polarity ....................................... 240 modulator signal sources ........................................ 237 modulator source pin disable ................................. 240 operation ................................................................. 237 operation in sleep mode ......................................... 240 programmable modulator data ................................ 240 slew rate control .................................................... 240 daw ................................................................................. 594 dc characteristics ctmu current source specifications ...................... 637 power-down and supply current ............................ 632 supply voltage ......................................................... 631 dcfsnz .......................................................................... 595 decf ............................................................................... 594 decfsz ........................................................................... 595 deep sleep brown-out reset (dsbor) ............................ 72 development support ...................................................... 625 device overview .................................................................. 9 features (100-pin devices) ....................................... 13 features (64-pin devices) ......................................... 12 features (80-pin devices) ......................................... 12 device reset timers oscillator start-up timer (ost) ................................. 95 pll lock time-out ..................................................... 95 power-up timer (pwrt) ........................................... 95 direct addressing ............................................................. 137 dsgprx registers saving context data .................................................. 76 e effect on standard pic18 instructions ............................. 622 electrical characteristics .................................................. 629 enhanced capture/compare/pwm (eccp) .................... 317 capture mode. see capture. compare mode. see compare. enhanced pwm mode ............................................. 323 auto-restart .................................................... 332 auto-shutdown ................................................ 330 direction change in full-bridge output mode . 329 full-bridge application ..................................... 327 full-bridge mode ............................................. 327 half-bridge application .................................... 326 half-bridge application example ..................... 333 half-bridge mode ............................................. 326 output relationships (active-high) ................. 324 output relationships (active-low) .................. 325 programmable dead-band delay .................... 333 shoot-through current .................................... 333 start-up considerations ................................... 330 outputs and configuration ....................................... 320 timer resources ..................................................... 320 enhanced universal synchronous asynchronous receiver transmitter (eusart). see eusart. equations 16 x 16 signed multiplication algorithm ................... 166 16 x 16 unsigned multiplication algorithm ............... 166 bytes transmitted for a given dmabc ................... 367 calculating usb transceiver current ...................... 548 estimating usb transceiver current consumption 547 lcd static, dynamic current .................................. 263 pwm duty cycle (in time) ...................................... 349 pwm period calculation .......................................... 348 pwm resolution ...................................................... 349 errata ................................................................................... 7 eusart asynchronous mode ................................................ 421 12-bit break transmit and receive ................. 426 auto-wake-up on sync break ......................... 424 receiver .......................................................... 423 setting up 9-bit mode with address detect .... 423 transmitter ...................................................... 421 baud rate generator operation in power-managed mode ................ 416 baud rate generator (brg) ................................... 416 auto-baud rate detect .................................... 419 baud rate error, calculating ........................... 416 baud rates, asynchronous modes ................. 417 high baud rate select (brgh bit) ................. 416 sampling ......................................................... 416 infrared support ....................................................... 431 built-in irda encoder, decoder ....................... 432 external, irda clock output ............................ 431 synchronous master mode ...................................... 427 reception ........................................................ 429 transmission ................................................... 427 synchronous slave mode ........................................ 430 reception ........................................................ 430 transmission ................................................... 430 extended instruction set addfsr .................................................................. 618 addulnk ............................................................... 618 callw .................................................................... 619 movsf .................................................................... 619 movss .................................................................... 620 pushl ..................................................................... 620 subfsr .................................................................. 621 subulnk ................................................................ 621
pic18f97j94 family ds30575a-page 682 ? 2012 microchip technology inc. external clock input ........................................................... 52 external memory bus ....................................................... 153 16-bit byte select mode .......................................... 159 16-bit byte write mode ............................................ 157 16-bit data width modes ......................................... 156 16-bit mode timing .................................................. 160 16-bit word write mode ........................................... 158 8-bit data width mode ............................................. 161 8-bit mode timing .................................................... 162 address and data lines for different address and data widths (table) ................................... 155 address and data width .......................................... 155 address shifting ....................................................... 155 control ..................................................................... 154 i/o port functions .................................................... 153 operation in power-managed modes ...................... 163 program memory modes ......................................... 156 extended microcontroller ................................. 156 microcontroller ................................................. 156 wait states ............................................................... 156 weak pull-ups on port pins ..................................... 156 f fail-safe clock monitor ............................................ 553, 571 exiting operation ..................................................... 571 interrupts in power-managed modes ....................... 572 por or wake from sleep ........................................ 572 wdt during oscillator failure ................................. 571 fail-safe clock monitor (fscm) ........................................ 57 and wdt .................................................................... 57 delay .......................................................................... 57 slow oscillator start-up ............ ................................. 57 family member details ...................................................... 11 fast register stack .......................................................... 117 firmware instructions ....................................................... 575 flash program memory .................................................... 143 control registers ..................................................... 144 eecon1 and eecon2 ................................... 144 tablat (table latch) ..................................... 146 tblptr (table pointer) .................................. 146 operations with tblrd, tblwt ............. 146 erase sequence ...................................................... 148 erasing ..................................................................... 148 operation during code-protect ............................... 152 reading .................................................................... 147 table pointer boundaries ........................................ 146 based on operation ......................................... 146 table reads, table writes ...................................... 143 write sequence ....................................................... 149 writing ...................................................................... 149 unexpected termination .................................. 152 write sequence ............................................... 151 write verify ...................................................... 152 fscm. see fail-safe clock monitor. g getting started guidelines ................................................. 31 goto ............................................................................... 596 h hardware multiplier .......................................................... 165 8 x 8 multiplication algorithms ................................. 165 operation ................................................................. 165 performance comparison (table) ............................. 165 high/low-voltage detect ................................................. 501 applications .............................................................. 505 current consumption ............................................... 503 effects of a reset .................................................... 505 operation ................................................................. 502 during sleep .................................................... 505 setup ....................................................................... 503 start-up time ........................................................... 503 typical application ................................................... 505 hlvd. see high/low-voltage detect. ............................. 501 i i/o ports ........................................................................... 197 open-drain outputs ................................................. 199 output pin drive ...................................................... 197 pin capabilities ........................................................ 197 pps-lite .................................................................. 224 pull-up configuration ............................................... 197 virtual port ............................................................ 224 i 2 c mode (mssp) acknowledge sequence timing .............................. 404 baud rate generator .............................................. 397 bus collision during a repeated start condition .................. 408 during a stop condition .................................. 409 clock arbitration ...................................................... 398 clock stretching ....................................................... 390 10-bit slave receive mode (sen = 1) ............ 390 10-bit slave transmit mode ............................ 390 7-bit slave receive mode (sen = 1) .............. 390 7-bit slave transmit mode .............................. 390 clock synchronization and the ckp bit ................... 391 effects of a reset .................................................... 405 general call address support ................................. 394 i 2 c clock rate w/brg ............................................. 397 master mode ............................................................ 395 operation ......................................................... 396 reception ........................................................ 401 repeated start condition timing .................... 400 start condition timing ..................................... 399 transmission ................................................... 401 multi-master communication, bus collision and arbitration ................................................. 405 multi-master mode ................................................... 405 operation ................................................................. 380 read/write bit information (r/w bit) ............... 380, 383 registers ................................................................. 372 serial clock (rc3/sckx/sclx) ............................... 383 slave mode .............................................................. 380 address masking modes 5-bit ......................................................... 381 7-bit ......................................................... 382 addressing ....................................................... 380 reception ........................................................ 383 transmission ................................................... 383 sleep operation ....................................................... 405 stop condition timing ............................................. 404 id locations ..................................................................... 553 incf ................................................................................ 596 incfsz ............................................................................ 597 in-circuit debugger .......................................................... 573 in-circuit serial programming (icsp) ...................... 553, 573 indexed literal offset addressing and standard pic18 instructions ............................. 622 indexed literal offset mode ............................................. 622 indirect addressing .......................................................... 137 infsnz ............................................................................ 597 initialization conditions for all registers .................... 97?112
? 2012 microchip technology inc. ds30575a-page 683 pic18f97j94 family instruction cycle .............................................................. 118 clocking scheme ..................................................... 118 flow/pipelining ......................................................... 118 instruction set .................................................................. 575 addlw .................................................................... 581 addwf .................................................................... 581 addwf (indexed literal offset mode) .................... 623 addwfc ................................................................. 582 andlw .................................................................... 582 andwf .................................................................... 583 bc ............................................................................ 583 bcf .......................................................................... 584 bn ............................................................................ 584 bnc ......................................................................... 585 bnn ......................................................................... 585 bnov ....................................................................... 586 bnz .......................................................................... 586 bov ......................................................................... 589 bra .......................................................................... 587 bsf .......................................................................... 587 bsf (indexed literal offset mode) .......................... 623 btfsc ..................................................................... 588 btfss ..................................................................... 588 btg .......................................................................... 589 bz ............................................................................ 590 call ........................................................................ 590 clrf ........................................................................ 591 clrwdt .................................................................. 591 comf ...................................................................... 592 cpfseq .................................................................. 592 cpfsgt .................................................................. 593 cpfslt ................................................................... 593 daw ......................................................................... 594 dcfsnz .................................................................. 595 decf ....................................................................... 594 decfsz ................................................................... 595 extended instructions .............................................. 617 considerations when enabling ........................ 622 syntax .............................................................. 617 use with mplab ide tools ............................. 624 general format ........................................................ 577 goto ...................................................................... 596 incf ......................................................................... 596 incfsz .................................................................... 597 infsnz .................................................................... 597 iorlw ..................................................................... 598 iorwf ..................................................................... 598 lfsr ........................................................................ 599 movf ....................................................................... 599 movff .................................................................... 600 movlb .................................................................... 600 movlw ................................................................... 601 movwf ................................................................... 601 mullw .................................................................... 602 mulwf .................................................................... 602 negf ....................................................................... 603 nop ......................................................................... 603 opcode field descriptions ....................................... 576 pop ......................................................................... 604 push ....................................................................... 604 rcall ..................................................................... 605 reset ..................................................................... 605 retfie .................................................................... 606 retlw .................................................................... 606 return .................................................................. 607 rlcf ....................................................................... 607 rlncf ..................................................................... 608 rrcf ....................................................................... 608 rrncf .................................. .................................. 609 setf ....................................................................... 609 setf (indexed literal offset mode) ........................ 623 sleep ..................................................................... 610 standard instructions ............................................... 575 subfwb ................................................................. 610 sublw .................................................................... 611 subwf .................................................................... 611 subwfb ................................................................. 612 swapf .................................................................... 612 tblrd ..................................................................... 613 tblwt .................................................................... 614 tstfsz ................................................................... 615 xorlw ................................................................... 615 xorwf ................................................................... 616 inter-integrated circuit. see i 2 c. internal fast rc oscillator (frc) ...................................... 56 enabling ..................................................................... 56 postscaler mode (frcdiv) ....................................... 56 with pll mode (frcpll) .......................................... 56 internal low-power rc oscillator (lprc) ......................... 57 enabling ..................................................................... 57 internal rc oscillator use with wdt .......................................................... 568 internal voltage regulator specifications ........................ 638 internet address .............................................................. 691 interrupt sources ............................................................. 553 capture complete (ccp) ........................................ 345 capture complete (eccp) ...................................... 321 compare complete (ccp) ...................................... 346 compare complete (eccp) .................................... 322 tmr0 overflow ........................................................ 283 tmr2 to pr2 match (pwm) .................................... 348 tmrx overflow ................................................ 284, 293 interrupts ......................................................................... 167 during, context saving ............................................ 195 edge-selectable interrupt-on-change ..................... 193 intx pin ................................................................... 193 tmr0 ....................................................................... 193 iorlw ............................................................................. 598 iorwf ............................................................................. 598 l lcd bias configurations ................................................. 259 bias types ............................................................... 252 charge pump design considerations ..................... 263 clock source selection ........................................... 251 configuring .............................................................. 279 frame frequency .................................................... 264 internal resistor biasing .......................................... 252 interrupts ................................................................. 278 multiplex types ........................................................ 264 operation during sleep ........................................... 279 pixel control ............................................................ 264 segment enables .................................................... 264 segment pins configuration .................................... 249 waveform generation ............................................. 265 lcd controller ........................................................... 10, 245 lfsr ............................................................................... 599
pic18f97j94 family ds30575a-page 684 ? 2012 microchip technology inc. m master synchronous serial port (mssp). see mssp. memory organization ....................................................... 113 data memory ........................................................... 120 program memory maps ........................................... 113 memory programming requirements .............................. 637 microchip internet web site ............................................. 691 movf ............................................................................... 599 movff ............................................................................. 600 movlb ............................................................................. 600 movlw ............................................................................ 601 movsf ............................................................................ 619 movss ............................................................................ 620 movwf ........................................................................... 601 mplab asm30 assembler, linker, librarian .................. 626 mplab integrated development environment software . 625 mplab pm3 device programmer .................................... 628 mplab real ice in-circuit emulator system ................ 627 mplink object linker/mplib object librarian ............... 626 mssp ack pulse ........................................................ 380, 383 i 2 c mode. see i 2 c mode. module overview ..................................................... 351 spi master/slave connection .................................. 357 tmrx output for clock shift .................................... 295 mullw ............................................................................ 602 mulwf ............................................................................ 602 n negf ............................................................................... 603 nop ................................................................................. 603 o oscillator clock switching mode configuration bits .................. 40 configuration .............................................................. 39 control registers ....................................................... 40 cpu clocking scheme .............................................. 38 osc1, osc2 pin functions in non-crystal modes ... 40 oscillator selection .......................................................... 553 oscillator, timer1/3/5 ....................................................... 284 p p1a/p1b/p1c/p1d. see enhanced capture/compare/ pwm (eccp). .......................................................... 323 packaging ........................................................................ 663 details ...................................................................... 665 marking .................................................................... 664 parallel slave port (psp) ................................................. 221 portd .................................................................... 221 peripheral power control ................................................... 79 disabling modules ...................................................... 79 module disable bit (xxmd) ............................................ 79 module enable bit (xxxen) ...................................... 79 phase lock loop (pll) ...................................................... 52 lock status ................................................................ 55 pinout i/o descriptions ................................................ 17?29 pop .................................................................................. 604 por. see power-on reset. porta lata register .......................................................... 201 porta register ...................................................... 201 trisa register ........................................................ 201 portb latb register ......................................................... 203 portb register ...................................................... 203 trisb register ........................................................ 203 portc latc register ......................................................... 205 portc register ...................................................... 205 rc3/sckx/sclx pin ............................................... 383 trisc register ........................................................ 205 portd latd register ......................................................... 207 portd register ...................................................... 207 trisd register ........................................................ 207 porte late register ......................................................... 209 porte register ...................................................... 209 re0/ad8/lcdbias1/rp28/rd pin ......................... 221 re1/ad9/lcdbias2/rp29/wr pin ........................ 221 re2/ad10/lcdbias3/rp30//cs pin ...................... 221 trise register ........................................................ 209 portf latf register .......................................................... 211 portf register ...................................................... 211 trisf register ........................................................ 211 portg latg register ......................................................... 213 portg register ...................................................... 213 trisg register ....................................................... 213 porth lath register ......................................................... 215 porth register ...................................................... 215 trish register ........................................................ 215 portj latj register .......................................................... 217 portj register ....................................................... 217 trisj register ........................................................ 217 portk latk register ......................................................... 219 portk register ...................................................... 219 trisk register ........................................................ 219 portl latl register .......................................................... 220 portl register ...................................................... 220 trisl register ........................................................ 220 power-managed modes and eusart operation .......................................... 416 and pwm operation ................................................ 337 and spi operation ................................................... 361 power-saving modes ......................................................... 65 clock source considerations .................................... 69 instruction-based ....................................................... 67 summary of features ................................................ 66 vbat ........................................................................... 75 wake-up ............................................................ 76 vbati/o pins .............................................................. 76 prescaler, timer0 ............................................................ 283 prescaler, timer2 ............................................................ 349 primary oscillator (posc) ................................................. 49 crystal oscillators, ceramic resonators ................... 50 operating modes ....................................................... 49 selecting .................................................................... 50 program counter ............................................................. 115 pcl, pch and pcu registers ................................ 115 pclath and pclatu registers ............................ 115 program memory code protection ....................................................... 573
? 2012 microchip technology inc. ds30575a-page 685 pic18f97j94 family extended instruction set .......................................... 138 hard memory vectors .............................................. 114 instructions ............................................................... 119 two-word ........................................................ 119 interrupt vector ........................................................ 114 look-up tables ........................................................ 117 organization ............................................................. 114 reset vector ............................................................ 114 programming, device instructions ................................... 575 psp. see parallel slave port. pulse steering .................................................................. 334 pulse-width modulation. see pwm (ccp module). push ............................................................................... 604 push and pop instructions ............................................ 116 pushl ............................................................................. 620 pwm (ccp module) duty cycle ................................................................ 349 example frequencies/resolutions .......................... 349 period ....................................................................... 348 setup for pwm operation ........................................ 349 tmr2 to pr2 match ................................................ 348 pwm (eccp module) effects of a reset ..................................................... 337 operation in power-managed modes ...................... 337 operation with fail-safe clock monitor ................... 337 pulse steering mode ................................................ 334 steering synchronization ......................................... 336 pwm mode. see enhanced capture/compare/pwm ..... 323 q q clock ............................................................................ 349 r ram. see data memory. rcall ............................................................................. 605 rconx bit operation on resets and wake-ups ............... 96 reader response ............................................................ 692 real-time clock and calendar (rtcc) ........................... 297 registers .................................................................. 298 reference clock output ..................................................... 45 applications ................................................................ 62 enable signal ............................................................. 63 operation in sleep ............................................... 45, 63 refo1, refo2 ......................................................... 62 source .................................................................. 45, 62 synchronization ................................................... 45, 63 register file ..................................................................... 122 register file summary ............................................ 124?135 registers actcon (active clock tuning control) .................... 61 adchs0h (a/d sample select 0 high) ................... 448 adchs0l (a/d sample select 0 low) .................... 449 adcon1h (a/d control 1 high) .............................. 441 adcon1l (a/d control 1 low) ............................... 442 adcon2h (a/d control 2 high) .............................. 443 adcon2l (a/d control 2 low) ............................... 444 adcon3h (a/d control 3 high) .............................. 445 adcon3l (a/d control 3 low) ............................... 445 adcon5h (a/d control 5 high) ........................................ 446 adcon5l (a/d control 5 low) ............................... 447 adcss0h (a/d input scan select 0 high) .............. 453 adcss0l (a/d input scan select 0 low) ............... 453 adcss1h (a/d input scan select 1 high) .............. 452 adcss1l (a/d input scan select 1 low) ............... 452 adctmuen0h (ctmu enable 0 high) ................... 455 adctmuen0l (ctmu enable,0 low) .................... 455 adctmuen1h (ctmu enable 1 high) .................. 454 adctmuen1l (ctmu enable 1 low) .................... 454 adhit0h (a/d scan compare hit 0 high) .............. 451 adhit0l (a/d scan compare hit 0 low) ............... 451 adhit1h (a/d scan compare hit 1 high) .............. 450 adhit1l (a/d scan compare hit 1 low) ............... 450 alrmcfg (alarm configuration) ............................ 302 alrmday (alarm day value) ................................. 307 alrmhr (alarm hours value) ................................ 308 alrmmin (alarm minutes value) ........................... 309 alrmmnth (alarm month value) .......................... 307 alrmrpt (alarm repeat) ...................................... 303 alrmsec (alarm seconds value) ......................... 309 alrmwd (alarm weekday value) .......................... 308 ancon1 (analog select control 1) ........................ 438 ancon2 (analog select control 2) ........................ 439 ancon3 (analog select control 3) ........................ 440 baudconx (baud rate control x) ......................... 414 bdnstat ................................................................ 535 bdnstat (buffer descriptor n status, cpu mode) 536 bdnstat (buffer descriptor n status, sie mode) .. 537 bdnstat (sie mode) ............................................. 537 buffer descriptors, summary .................................. 539 ccprxh (ccpx period high byte) ......................... 342 ccprxl (ccpx period low byte) ........................... 342 ccptmrs0 (ccp timer select 0) .......................... 319 ccptmrs1 (ccp timer select 1) .......................... 340 ccptmrs2 (ccp timer select 2) .......................... 341 ccpxcon (ccp4-ccp10 control) ......................... 339 ccpxcon (enhanced capture/compare/pwmx control) ............................................................ 318 cmstat (comparator status) ................................ 491 cmxcon (comparator control x) ........................... 490 config1h (configuration 1 high) .......................... 555 config1l (configuration 1 low) ........................... 555 config2h (configuration 2 high) .......................... 557 config2l (configuration 2 low) ........................... 556 config3l (configuration 3 low) ........................... 558 config4h (configuration 4 high) .......................... 559 config4l (configuration 4 low) ........................... 559 config5h (configuration 5 high) .......................... 561 config5l (configuration 5 low) ........................... 560 config6h (configuration 6 high) .......................... 563 config6l (configuration 6 low) ........................... 562 config7l (configuration 7 low) ........................... 564 config8h (configuration 8 high) .......................... 566 config8l (configuration 8 low) ........................... 565 ctmucon (ctmu control) .................................... 508 ctmucon1 (ctmu current control 1) .................. 509 ctmucon2 (ctmu current control 2) .................. 510 ctmucon3 (ctmu current control 3) .................. 511 cvrconh (comparator voltage reference control high) ................................................... 497 cvrconl (comparator voltage reference control low) .................................................... 498 day (day value) ..................................................... 305 devid1 (device id 1) .............................................. 567 devid2 (device id 2) .............................................. 567 dmacon1 (dma control 1) .................................... 364 dmacon2 (dma control 2) .................................... 365 dsconh (deep sleep control high) ........................ 77 dsconl (deep sleep control low) ......................... 77 dswakeh (deep sleep wake-up source high) ...... 78 dswakel (deep sleep wake-up source low) ....... 78
pic18f97j94 family ds30575a-page 686 ? 2012 microchip technology inc. eccpxas (eccpx auto-shutdown control) ........... 331 eccpxdel (enhanced pwm control) .................... 334 eecon1 (eeprom control 1) ................................ 145 hlvdcon (high/low-voltage detect control) ........ 501 hour (hour value) ................................................. 305 intcon (interrupt control) ...................................... 170 intcon2 (interrupt control 2) ................................. 171 intcon3 (interrupt control 3) ................................. 172 iocf (interrupt-on-change flag) ............................. 194 iocn (interrupt-on-change negative edge) ............ 194 iocp (interrupt-on-change positive edge) ............. 194 ipr1 (peripheral interrupt priority 1) ........................ 186 ipr2 (peripheral interrupt priority 2) ........................ 187 ipr3 (peripheral interrupt priority 3) ........................ 188 ipr4 (peripheral interrupt priority 4) ........................ 189 ipr5 (peripheral interrupt priority 5) ........................ 190 ipr6 (peripheral interrupt priority 6) ........................ 191 lcdcon (lcd control) ........................................... 246 lcddatax (lcd data x) ........................................ 250 lcdps (lcd phase) ............................................... 248 lcdrefh (lcd reference ladder control high) ... 256 lcdrefl (lcd reference ladder control low) .... 257 lcdreg (lcd charge pump control) .................... 247 lcdreg (lcd voltage regulator control) ............. 258 lcdsex (lcd segment x enable) .......................... 249 mdcarh (modulation carrier high control) ... 243, 244 mdcon (modulation control register) ................... 241 mdsrc (modulation source control) ...................... 242 memcon (external memory bus control) .............. 154 minute (minute value) ........................................... 306 month (month value) ............................................ 304 odcon1 (peripheral open-drain control 1) ........... 199 odcon2 (peripheral open-drain control 2) ........... 200 osccon (oscillator control) .................................... 41 osccon2 (oscillator control 2) ............................... 42 osccon3 (oscillator control 3) ............................... 43 osccon4 (oscillator control 4) ............................... 43 osctune (frc oscillator tuning) ........................... 44 padcfg (pad configuration) .................................. 198 pie1 (peripheral interrupt enable 1) ........................ 180 pie2 (peripheral interrupt enable 2) ........................ 181 pie3 (peripheral interrupt enable 3) ........................ 182 pie4 (peripheral interrupt enable 4) ........................ 183 pie5 (peripheral interrupt enable 5) ........................ 184 pie6 (peripheral interrupt enable 6) ........................ 185 pir1 (peripheral interrupt request (flag) 1) ........... 173 pir2 (peripheral interrupt request (flag) 2) ........... 174 pir3 (peripheral interrupt request (flag) 3) ........... 175 pir4 (peripheral interrupt request (flag) 4) ........... 176 pir5 (peripheral interrupt request (flag) 5) ........... 178 pir6 (peripheral interrupt request (flag) 6) ........... 179 pspcon (parallel slave port control) .................... 222 pstrxcon (pulse steering control) ...................... 335 rcon (reset control 1) .................................... 86, 192 rcon2 (reset control 2) .................................. 87, 569 rcon3 (reset control 3) .......................................... 88 rcon4 (reset control 4) .......................................... 89 rcstax (eusartx receive status and control) ... 413 refoxcon (reference clock output control) ......... 46 refoxcon1 (reference clock output control 1) .... 47 refoxcon2 (reference clock output control 2) .... 48 refoxcon3 (reference clock output control 3) .... 48 reserved .................................................................. 303 rporn_n (remapped peripheral output n) ........... 230 rtccal (rtcc calibration) ................................... 300 rtccon1 (rtcc configuration 1) ......................... 299 rtccon2 (rtc configuration) .............................. 301 second (second value) ........................................ 306 sspxcon1 (msspx control 1, i 2 c master mode) .. 374 sspxcon1 (msspx control 1, spi mode) ................................ 354, 355, 376, 378 sspxcon2 (msspx control 2, i 2 c master mode) .. 375 sspxcon2 (msspx control 2, i 2 c slave mode) .... 377 sspxmsk (i 2 c slave address mask, 7-bit masking mode) ................................................ 379 sspxstat (msspx status, i 2 c master mode) ....... 373 sspxstat (msspx status, spi mode) .................. 353 status .................................................................. 135 stkptr (stack pointer) .......................................... 116 t0con (timer0 control) ......................................... 281 txcon (timerx control, timer1/3/5) ....................... 285 txcon (timerx control, timer2/4/6/8) .................... 295 txgcon (timerx gate control) .............................. 286 txstax (eusartx transmit status and control) .. 412 uaddr .................................................................... 533 ucfg (usb configuration) ..................................... 529 ucon (usb control) ............................................... 527 ueie (usb error interrupt enable) .......................... 545 ueir (usb error interrupt status) ........................... 544 uepn (usb endpoint n control) .............................. 532 ufrmh:ufrml ...................................................... 533 uie (usb interrupt enable) ..................................... 543 uir (usb interrupt status) ...................................... 541 ustat (usb status) ............................................... 531 weekday (weekday value) .................................. 305 year (year value) .................................................. 304 reset ............................................................................. 605 reset ................................................................................. 85 brown-out reset (bor) features ............................................................ 93 configuration mismatch (cm) .................................... 93 master clear (mclr ) ................................................. 92 power-on reset (por) .............................................. 90 rcon registers ........................................................ 85 reset instruction ..................................................... 94 stack underflow/overflow ......................................... 94 watchdog timer reset (wdt) .................................. 92 resets ........................................................................ 85, 553 brown-out reset (bor) ........................................... 553 oscillator start-up timer (ost) ............................... 553 power-on reset (por) ............................................ 553 power-up timer (pwrt) ......................................... 553 retention sleep mode delay times for exit (table) ....................................... 70 retfie ............................................................................ 606 retlw ............................................................................ 606 return .......................................................................... 607 return address stack ...................................................... 115 return stack pointer (stkptr) ...................................... 116 revision history ............................................................... 677 rlcf ............................................................................... 607 rlncf ............................................................................. 608 rrcf ............................................................................... 608 rrncf ................... ......................................................... 609 rtcc alarm ....................................................................... 313 configuring ...................................................... 313 interrupt ........................................................... 314 mask settings .................................................. 314 alarm value registers (alrmval) ......................... 307
? 2012 microchip technology inc. ds30575a-page 687 pic18f97j94 family associated alarm value registers ........................... 316 associated control registers ................................... 316 associated value registers ..................................... 316 control registers ..................................................... 299 operation ................................................................. 310 calibration ........................................................ 313 clock source ................................................... 311 digit carry rules .............................................. 311 general functionality ....................................... 312 leap year ........................................................ 312 register mapping ............................................. 312 alrmval ................................................ 313 rtcval ................................................... 312 safety window for register reads and writes 312 write lock ........................................................ 312 register interface ..................................................... 310 register maps .......................................................... 316 reset ........................................................................ 315 device .............................................................. 315 power-on reset (por) .................................... 315 rtcen bit write ...................................................... 310 sleep mode .............................................................. 315 value registers (rtcval) ...................................... 303 s secondary oscillator (sosc) ............................................ 55 enabling ..................................................................... 55 serial peripheral interface. see spi mode. setf ................................................................................ 609 shoot-through current .................................................... 333 sleep ............................................................................. 610 sleep mode delay times for exit (table) ........................................ 70 software simulator (mplab sim) .................................... 627 special event trigger. see compare (ccp module). special event trigger. see compare (eccp mode). spi mode (mssp) ............................................................ 352 bus mode compatibility ........................................... 361 clock speed, interactions ........................................ 361 dma module ............................................................ 362 i/o pin considerations ..................................... 362 idle, sleep considerations ............................... 362 ram to ram copy operations ........................ 362 registers .......................................................... 362 effects of a reset ..................................................... 361 enabling spi i/o ...................................................... 357 master mode ............................................................ 358 master/slave connection ......................................... 357 operation ................................................................. 356 operation in power-managed modes ...................... 361 slave mode .............................................................. 359 slave select synchronization .................................. 359 spi clock ................................................................. 358 sspxbuf register .................................................. 358 sspxsr register ..................................................... 358 typical connection .................................................. 357 sspov ............................................................................. 401 sspov status flag ......................................................... 401 sspxstat register r/w bit ............................................................. 380, 383 st block diagram ............................................................ 60 stack full/underflow resets ............................................ 117 subfsr .......................................................................... 621 subfwb .......................................................................... 610 sublw ............................................................................ 611 subulnk ........................................................................ 621 subwf ............................................................................ 611 subwfb ......................................................................... 612 swapf ............................................................................ 612 t table reads/table writes ............................................... 117 tblrd ............................................................................. 613 tblwt ............................................................................ 614 timer0 ............................................................................. 281 operation ................................................................. 282 overflow interrupt .................................................... 283 prescaler ................................................................. 283 switching assignment ..................................... 283 prescaler assignment (psa bit) .............................. 283 prescaler select (t0ps2:t0ps0 bits) ..................... 283 reads and writes in 16-bit mode ............................ 282 timer1/3/5 ....................................................................... 284 16-bit read/write mode .......................................... 288 gates ....................................................................... 289 operation ................................................................. 287 oscillator .................................................................. 284 overflow interrupt ............................................ 284, 293 special event trigger (eccp) ................................. 293 tmrxh register ...................................................... 284 tmrxl register ....................................................... 284 using sosc oscillator as clock source ................. 288 timer2 pr2 register ........................................................... 348 tmr2 to pr2 match interrupt .................................. 348 timer2/4/6/8 .................................................................... 294 interrupt ................................................................... 295 mssp clock shift .................................................... 295 operation ................................................................. 294 output ...................................................................... 295 postscaler. see postscaler, timer2/4/6/8. prescaler. see prescaler, timer2/4/6/8. prx register ........................................................... 294 tmrx register ......................................................... 294 timing diagrams ?0? bit data irda encoding scheme ......................... 432 a/d conversion ....................................................... 661 asynchronous reception ......................................... 424 asynchronous transmission ................................... 422 asynchronous transmission (back-to-back) ........... 422 automatic baud rate calculation ............................ 420 auto-sample start, conversion trigger based conversion start .............................................. 465 auto-wake-up bit (wue) during normal operation 425 auto-wake-up bit (wue) during sleep ................... 425 baud rate generator with clock arbitration ............ 398 bclk output vs. brg programming ...................... 431 brg overflow sequence ........................................ 420 brg reset due to sdax arbitration during start condition ................................................. 407 brown-out reset (bor) ........................................... 647 bus collision during repeated start condition (case 1) ........................................................... 408 bus collision during repeated start condition (case 2) ........................................................... 408 bus collision during start condition (sclx = 0) ..... 407 bus collision during start condition (sdax only) .. 406 bus collision during stop condition (case 1) ......... 409 bus collision during stop condition (case 2) ......... 409 bus collision for transmit and acknowledge .......... 405 capture/compare/pwm (ccp1, ccp2) .................. 650
pic18f97j94 family ds30575a-page 688 ? 2012 microchip technology inc. clko and i/o .......................................................... 644 clock jitter causing pulse between consecutive zeros ................................................................ 433 clock synchronization ............................................. 391 clock transition ......................................................... 58 clock/instruction cycle ...................................... 38, 118 converting 1 channel 16 times per interrupt .......... 477 converting 1 channel, auto-sample start, manual conversion start .............................................. 462 converting 1 channel, auto-sample start, t ad ad based conversion start ................................... 464 converting 1 channel, manual sample start, t ad ad based conversion start ........................ 463 converting 2 inputs using alternating input selections ........................................................ 483 converting a single channel, once per interrupt using dual, 8-word buffers ............................. 481 dsm carrier high synchronization (mdchsync = 1, mdclsync = 0) ............... 238 dsm carrier low synchronization (mdchsync = 0, mdclsync = 1) ............... 239 dsm full synchronization (mdchsync = 1, mdclsync = 1) ............................................. 239 dsm no synchronization (mdchsync = 0, mdclsync = 0) ............................................. 238 dsm on-off keying (ook) synchronization ........... 238 eusartx synchronous transmission (master/slave) .................................................. 659 eusartx/ausartx synchronous receive (master/slave) .................................................. 659 example spi master mode (cke = 0) ..................... 651 example spi master mode (cke = 1) ..................... 652 example spi slave mode (cke = 0) ....................... 653 example spi slave mode (cke = 1) ....................... 654 external clock .......................................................... 642 external memory bus for sleep (extended microcontroller mode) .............................. 160, 162 external memory bus for tblrd (extended microcontroller mode) .............................. 160, 162 fail-safe clock monitor (fscm) .............................. 572 first start bit timing ................................................ 399 full-bridge pwm output .......................................... 328 half-bridge pwm output ................................. 326, 333 high-voltage detect operation (vdirmag = 1) ...... 504 hlvd characteristics ............................................... 648 i 2 c acknowledge sequence .................................... 404 i 2 c bus data ............................................................ 656 i 2 c bus start/stop bits ............................................. 655 i 2 c master mode (7 or 10-bit transmission) ........... 402 i 2 c master mode (7-bit reception) .......................... 403 i 2 c slave mode (10-bit reception, sen = 0, msk = 01001) .................................................. 387 i 2 c slave mode (10-bit recepti on, sen = 0) .......... 388 i 2 c slave mode (10-bit recepti on, sen = 1) .......... 393 i 2 c slave mode (10-bit transmission) ..................... 389 i 2 c slave mode (7-bit reception, sen = 0, msk = 01011) .................................................. 385 i 2 c slave mode (7-bit reception, sen = 0) ............ 384 i 2 c slave mode (7-bit reception, sen = 1) ............ 392 i 2 c slave mode (7-bit transmission) ....................... 386 i 2 c slave mode general call address sequence (7 or 10-bit addressing mode) ................................. 394 i 2 c stop condition receive or transmit mode ........ 404 inverted irda encoding (txckp = 1) ...................... 432 inverted polarity decoding results (rxdtp = 1) .... 433 irda encoding scheme ........................................... 432 lcd reference ladder power mode switching ...... 254 lcd sleep entry/exit when slpen = 1 or cs1:cs0 = 00 ................................................. 280 low-voltage detect operation (vdirmag = 0) ...... 504 macro view of irda decoding scheme (rxdtp = 0) .................................................... 433 manual sample start, conversion trigger based conversion start .............................................. 465 msspx i 2 c bus data ............................................... 657 msspx i 2 c bus start/stop bits ............................... 657 parallel slave port (psp) read ............................... 223 parallel slave port (psp) write ............................... 222 por module for rising v dd ...................................... 91 program memory fetch (8-bit) ................................. 645 program memory read ........................................... 646 pwm auto-shutdown with auto-restart enabled (pxrsen = 1) .................................................. 332 pwm auto-shutdown with firmware restart (pxrsen = 0) .................................................. 332 pwm direction change ........................................... 329 pwm direction change at near 100% duty cycle .. 330 pwm output ............................................................ 348 pwm output (active-high) ...................................... 324 pwm output (active-low) ....................................... 325 repeated start condition ........................................ 400 reset, watchdog timer (wdt), oscillator start-up timer (ost) and power-up timer (pwrt) ..... 647 scanning all 16 inputs per single interrupt ............. 479 send break character sequence ............................ 426 slave synchronization ............................................. 359 spi mode (master mode) ......................................... 358 spi mode (slave mode, cke = 0) ........................... 360 spi mode (slave mode, cke = 1) ........................... 360 steering event at beginning of instruction (strsync = 1) ............................................... 336 steering event at end of instruction (strsync = 0) ............................................... 336 synchronous reception (master mode, sren) ...... 429 synchronous transmission ..................................... 428 synchronous transmission (through txen) .......... 428 timer pulse generation ........................................... 315 timer0 and timer1 external clock .......................... 649 timer1/3/5 gate count enable mode ...................... 289 timer1/3/5 gate single pulse mode ........................ 291 timer1/3/5 gate single pulse/toggle combined mode ................................................................ 292 timer1/3/5 gate toggle mode ................................. 290 transition for two-speed start-up (intosc to hspll) ........................................ 570 waveforms and interrupt in quarter duty cycle drive ................................................................ 278 timing diagrams and specifications capture/compare/pwm requirements ................... 650 clko and i/o requirements ........................... 644, 646 eusartx/ausartx synchronous receive requirements .................................................. 659 eusartx/ausartx synchronous transmission requirements .................................................. 659 example spi mode requirements (master mode, cke = 0) .......................................................... 651 example spi mode requirements (master mode, cke = 1) .......................................................... 652 example spi mode requirements (slave mode, cke = 0) .......................................................... 653
? 2012 microchip technology inc. ds30575a-page 689 pic18f97j94 family example spi slave mode requirements (cke = 1) 654 external clock requirements .................................. 642 hlvd characteristics ............................................... 648 i 2 c bus data requirements (slave mode) .............. 656 i 2 c bus start/stop bits requirements (slave mode) ................................................... 655 internal rc accuracy (intosc) .............................. 643 msspx i 2 c bus data requirements ........................ 658 msspx i 2 c bus start/stop bits requirements ........ 657 pll clock ................................................................. 643 program memory fetch requirements (8-bit) ......... 645 reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset requirements .................................................. 647 timer0 and timer1 external clock requirements ... 649 top-of-stack access ........................................................ 115 tstfsz ........................................................................... 615 two-speed start-up ........................................... 62, 553, 570 special considerations for use .................................. 62 two-word instructions example cases ........................................................ 119 txstax register brgh bit ................................................................. 416 u universal serial bus ......................................................... 525 address register (uaddr) ..................................... 533 associated registers ............................................... 549 buffer descriptor table ............................................ 534 buffer descriptors .................................................... 534 address validation ........................................... 537 assignment in different buffering modes ........ 539 bdnstat register (cpu mode) ..................... 535 bdnstat register (sie mode) ....................... 537 byte count ....................................................... 537 memory map .................................................... 538 ownership ........................................................ 534 ping-pong buffering ......................................... 538 register summary ........................................... 539 status and configuration ................................. 534 endpoint control ...................................................... 532 external pull-up resistors ........................................ 530 eye pattern test enable .......................................... 530 firmware and drivers ............................................... 549 frame number registers ......................................... 533 internal pull-up resistors ......................................... 530 internal transceiver ................................................. 528 interrupts .................................................................. 540 and usb transactions ..................................... 540 oscillator requirements ........................................... 549 overview .......................................................... 525, 550 class specifications and drivers ..................... 551 descriptors ....................................................... 551 enumeration .................................................... 551 frames ............................................................. 550 layered framework ......................................... 550 power ............................................................... 550 speed .............................................................. 551 transfer types ................................................. 550 ping-pong buffer configuration ............................... 530 power modes ........................................................... 546 bus power only ............................................... 546 dual power with self-power dominance ......... 546 self-power only ............................................... 546 transceiver current consumption ................... 547 ram ......................................................................... 533 memory map .................................................... 533 status and control ................................................... 526 ufrmh:ufrml registers ...................................... 533 usb module specifications .............................................. 639 usb. see universal serial bus. v voltage-frequency graph ............................................... 630 w watchdog timer (wdt) ........................................... 553, 568 control register ....................................................... 569 during oscillator failure .......................................... 571 programming considerations .................................. 568 wcol ...................................................... 399, 400, 401, 404 wcol status flag ................................... 399, 400, 401, 404 www address ................................................................ 691 www, on-line support .................... .................................. 7 x xorlw ........................................................................... 615 xorwf ........................................................................... 616
pic18f97j94 family ds30575a-page 690 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 691 pic18f97j94 family the microchip web site microchip provides online support via our www site at www.microchip.com . this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following information: ? product support ? data sheets and errata, application notes and sample programs, design resources, user?s guides and hardware support documents, latest software releases and archived software ? general technical support ? frequently asked questions (faq), technical support requests, online discussion groups, microchip consultant program member listing ? business of microchip ? product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of microchip sales offices, distributors and factory representatives customer change notification service microchip?s customer notification service helps keep customers current on microchip products. subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. to register, access the microchip web site at www.microchip.com . under ?support?, click on ?customer change notification? and follow the registration instructions. customer support users of microchip products can receive assistance through several channels: ? distributor or representative ? local sales office ? field application engineer (fae) ? technical support ? development systems information line customers should contact their distributor, representative or field application engineer (fae) for support. local sales offices are also available to help customers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://microchip.com/support
pic18f97j94 family ds30575a-page 692 ? 2012 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip product. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to: technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds30575a pic18f97j94 family 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2012 microchip technology inc. ds30575a-page 693 pic18f97j94 family product identification system to order or obtain information, e. g., on pricing or delivery, refer to the factory or the listed sales office . part no. x /xx xxx pattern package temperature range device device pic18f97j94, pic18f96j94, pic18f95j94, pic18f87j94, pic18f86j94, pic18f85j94, pic18f67j94, pic18f66j94, PIC18F65J94 v dd range 2.0 to 3.6v temperature range i = -40 ? c to +85 ? c (industrial) package pt = tqfp (thin quad flatpack) pf = tqfp (100-pin thin quad, 14x14x1 body) pattern qtp, sqtp, code or special requirements (blank otherwise) examples: a) pic18f97j94-i/pt = industrial temp., tqfp package, qtp pattern #301. b) pic18f87j94-i/pt = industrial temp., tqfp package. note 1: t = in tape and reel plcc, and tqfp packages only.
pic18f97j94 family ds30575a-page 694 ? 2012 microchip technology inc. notes:
? 2012 microchip technology inc. ds30575a-page 695 information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application meets with your specifications. microchip makes no representations or warranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip devices in life support and/or safety applications is entirely at the buyer?s risk, and the buyer agrees to defend, indemnify and hold harmless microchip from any and all damages, claims, suits, or expenses resulting from such use. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, dspic, flashflex, k ee l oq , k ee l oq logo, mplab, pic, picmicro, picstart, pic 32 logo, rfpic, sst, sst logo, superflash and uni/o are registered trademarks of microchip technology incorporated in the u.s.a. and other countries. filterlab, hampshire, hi-tech c, linear active thermistor, mtp, seeval and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. silicon storage technology is a registered trademark of microchip technology inc. in other countries. analog-for-the-digital age, app lication maestro, bodycom, chipkit, chipkit logo, codeguard, dspicdem, dspicdem.net, dspicworks, dsspeak, ecan, economonitor, fansense, hi-tide, in-circuit serial programming, icsp, mindi, miwi, mpasm, mpf, mplab certified logo, mplib, mplink, mtouch, omniscient code generation, picc, picc-18, picdem, picdem.net, pickit, pictail, real ice, rflab, select mode, sqi, serial quad i/o, total endurance, tsharc, uniwindriver, wiperlock, zena and z-scale are trademarks of microchip technology incorporated in the u.s.a. and other countries. sqtp is a service mark of microchip technology incorporated in the u.s.a. gestic and ulpp are registered trademarks of microchip technology germany ii gmbh & co. & kg, a subsidiary of microchip technology inc., in other countries. all other trademarks mentioned herein are property of their respective companies. ? 2012, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. isbn: 9781620766231 note the following details of the code protection feature on microchip devices: ? microchip products meet the specification cont ained in their particular microchip data sheet. ? microchip believes that its family of products is one of the most secure families of its kind on the market today, when used i n the intended manner and under normal conditions. ? there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specif ications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property. ? microchip is willing to work with the customer who is concerned about the integrity of their code. ? neither microchip nor any other semiconduc tor manufacturer can guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvin g the code protection features of our products. attempts to break microchip?s code protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2009 certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona; gresham, oregon and design centers in california and india. the company?s quality system processes and procedures are for its pic ? mcus and dspic ? dscs, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified. quality management s ystem certified by dnv == iso/ts 16949 ==
ds30575a-page 696 ? 2012 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://www.microchip.com/ support web address: www.microchip.com atlanta duluth, ga tel: 678-957-9614 fax: 678-957-1455 boston westborough, ma tel: 774-760-0087 fax: 774-760-0088 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 cleveland independence, oh tel: 216-447-0464 fax: 216-447-0643 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 indianapolis noblesville, in tel: 317-773-8323 fax: 317-773-5453 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 santa clara santa clara, ca tel: 408-961-6444 fax: 408-961-6445 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific asia pacific office suites 3707-14, 37th floor tower 6, the gateway harbour city, kowloon hong kong tel: 852-2401-1200 fax: 852-2401-3431 australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8569-7000 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8665-5511 fax: 86-28-8665-7889 china - chongqing tel: 86-23-8980-9588 fax: 86-23-8980-9500 china - hangzhou tel: 86-571-2819-3187 fax: 86-571-2819-3189 china - hong kong sar tel: 852-2401-1200 fax: 852-2401-3431 china - nanjing tel: 86-25-8473-2460 fax: 86-25-8473-2470 china - qingdao tel: 86-532-8502-7355 fax: 86-532-8502-7205 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8203-2660 fax: 86-755-8203-1760 china - wuhan tel: 86-27-5980-5300 fax: 86-27-5980-5118 china - xian tel: 86-29-8833-7252 fax: 86-29-8833-7256 china - xiamen tel: 86-592-2388138 fax: 86-592-2388130 china - zhuhai tel: 86-756-3210040 fax: 86-756-3210049 asia/pacific india - bangalore tel: 91-80-3090-4444 fax: 91-80-3090-4123 india - new delhi tel: 91-11-4160-8631 fax: 91-11-4160-8632 india - pune tel: 91-20-2566-1512 fax: 91-20-2566-1513 japan - osaka tel: 81-66-152-7160 fax: 81-66-152-9310 japan - yokohama tel: 81-45-471- 6166 fax: 81-45-471-6122 korea - daegu tel: 82-53-744-4301 fax: 82-53-744-4302 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 malaysia - kuala lumpur tel: 60-3-6201-9857 fax: 60-3-6201-9859 malaysia - penang tel: 60-4-227-8870 fax: 60-4-227-4068 philippines - manila tel: 63-2-634-9065 fax: 63-2-634-9069 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - hsin chu tel: 886-3-5778-366 fax: 886-3-5770-955 taiwan - kaohsiung tel: 886-7-536-4818 fax: 886-7-330-9305 taiwan - taipei tel: 886-2-2500-6610 fax: 886-2-2508-0102 thailand - bangkok tel: 66-2-694-1351 fax: 66-2-694-1350 europe austria - wels tel: 43-7242-2244-39 fax: 43-7242-2244-393 denmark - copenhagen tel: 45-4450-2828 fax: 45-4485-2829 france - paris tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - munich tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 spain - madrid tel: 34-91-708-08-90 fax: 34-91-708-08-91 uk - wokingham tel: 44-118-921-5869 fax: 44-118-921-5820 worldwide sales and service 11/29/11


▲Up To Search▲   

 
Price & Availability of PIC18F65J94

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X